blob: bdbffc9253582534c98064f539fabc9654bf587f [file] [log] [blame]
Finn Williams15db7452019-10-15 14:22:13 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "MockUtils.hpp"
7
8namespace armnn
9{
10
11namespace gatordmock
12{
13
14std::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
34std::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
49bool 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