Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "MockUtils.hpp" |
| 7 | |
| 8 | namespace armnn |
| 9 | { |
| 10 | |
| 11 | namespace gatordmock |
| 12 | { |
| 13 | |
| 14 | std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth) |
| 15 | { |
| 16 | std::stringstream outputStream, centrePadding; |
| 17 | int padding = spacingWidth - static_cast<int>(stringToPass.size()); |
| 18 | |
| 19 | for (int i = 0; i < padding / 2; ++i) |
| 20 | { |
| 21 | centrePadding << " "; |
| 22 | } |
| 23 | |
| 24 | outputStream << centrePadding.str() << stringToPass << centrePadding.str(); |
| 25 | |
| 26 | if (padding > 0 && padding %2 != 0) |
| 27 | { |
| 28 | outputStream << " "; |
| 29 | } |
| 30 | |
| 31 | return outputStream.str(); |
| 32 | } |
| 33 | |
| 34 | std::string GetStringNameFromBuffer(const unsigned char* const data, uint32_t offset) |
| 35 | { |
| 36 | std::string deviceName; |
| 37 | u_char nextChar = profiling::ReadUint8(data, offset); |
| 38 | |
| 39 | while (IsValidChar(nextChar)) |
| 40 | { |
| 41 | deviceName += static_cast<char>(nextChar); |
| 42 | offset ++; |
| 43 | nextChar = profiling::ReadUint8(data, offset); |
| 44 | } |
| 45 | |
| 46 | return deviceName; |
| 47 | } |
| 48 | |
| 49 | bool IsValidChar(unsigned char c) |
| 50 | { |
| 51 | // Check that the given character has ASCII 7-bit encoding, alpha-numeric, whitespace, and underscore only |
| 52 | return c < 128 && (std::isalnum(c) || c == '_' || c == ' '); |
| 53 | } |
| 54 | |
| 55 | } // gatordmock |
| 56 | |
| 57 | } // armnn |