Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
TestParseText.cpp
Go to the documentation of this file.
1/**
2 * @file TestParseText.cpp
3 * @brief Unit Test for ParseText()
4 * @author @h02332 | David Hoyt | @xsscx
5 * @date 24 MAY 2024
6 * @version 1.0.2
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * Compile: clang++ -std=c++17 -fsanitize=address -isysroot $(xcrun --show-sdk-path) -I$(xcrun --show-sdk-path)/usr/include/c++/v1 TestParseText.cpp -o TestParseText
22
23 *
24 *
25 */
26
27#include <iostream>
28#include <cstring>
29#include <cmath>
30
31// Mock the required environment and dependencies
32typedef unsigned int icUInt32Number;
34
35bool icIsNumChar(char c) {
36 return (c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+';
37}
38
39float nanf(const char* tagp) {
40 return std::nan("");
41}
42
43template <class T, icTagTypeSignature Tsig>
45public:
48
49 CIccXmlArrayType() : m_pBuf(nullptr), m_nSize(0) {}
50 ~CIccXmlArrayType() { delete[] m_pBuf; }
51
52 icUInt32Number ParseText(T* pBuf, icUInt32Number nSize, const char *szText);
53};
54
55template <class T, icTagTypeSignature Tsig>
57 icUInt32Number n = 0;
58 char num[256] = {0};
59 int b = 0;
60 bool bInNum = false;
61
62 while (*szText && n < nSize) {
63 if (icIsNumChar(*szText)) {
64 if (!bInNum) {
65 bInNum = true;
66 b = 0;
67 }
68 if (b < sizeof(num) - 2) {
69 num[b++] = *szText;
70 }
71 } else {
72 if (bInNum) {
73 num[b] = '\0';
74 pBuf[n++] = (T)atof(num);
75 bInNum = false;
76 }
77 }
78 szText++;
79 }
80
81 if (bInNum && n < nSize) {
82 num[b] = '\0';
83 pBuf[n++] = (T)atof(num);
84 }
85
86 return n;
87}
88
89int main() {
90 const char testInput[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
91 unsigned short buffer[100];
93
94 arrayType.ParseText(buffer, 100, testInput);
95
96 std::cout << "Test completed successfully.\n";
97 return 0;
98}
99
bool icIsNumChar(char c)
icTagTypeSignature
@ icSigUInt16ArrayType
float nanf(const char *tagp)
unsigned int icUInt32Number
int main()
icUInt32Number ParseText(T *pBuf, icUInt32Number nSize, const char *szText)
icUInt32Number m_nSize