aboutsummaryrefslogtreecommitdiff
path: root/tests/profiling/gatordmock/MockUtils.cpp
blob: bdbffc9253582534c98064f539fabc9654bf587f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright © 2019 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "MockUtils.hpp"

namespace armnn
{

namespace gatordmock
{

std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth)
{
    std::stringstream outputStream, centrePadding;
    int padding = spacingWidth - static_cast<int>(stringToPass.size());

    for (int i = 0; i < padding / 2; ++i)
    {
        centrePadding << " ";
    }

    outputStream << centrePadding.str() << stringToPass << centrePadding.str();

    if (padding > 0 && padding %2 != 0)
    {
        outputStream << " ";
    }

    return outputStream.str();
}

std::string GetStringNameFromBuffer(const unsigned char* const data, uint32_t offset)
{
    std::string deviceName;
    u_char nextChar = profiling::ReadUint8(data, offset);

    while (IsValidChar(nextChar))
    {
        deviceName += static_cast<char>(nextChar);
        offset ++;
        nextChar = profiling::ReadUint8(data, offset);
    }

    return deviceName;
}

bool IsValidChar(unsigned char c)
{
    // Check that the given character has ASCII 7-bit encoding, alpha-numeric, whitespace, and underscore only
    return c < 128 && (std::isalnum(c) || c == '_' || c == ' ');
}

} // gatordmock

} // armnn