hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/******************************************************************************
*
* Copyright(c) 2019 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
 
#include "hal_str_proc.h"
 
 
bool hal_is_comment_string(
       char            *szStr
)
{
   if (*szStr == '/' && *(szStr + 1) == '/')
       return true;
   else
       return false;
}
 
bool hal_get_fractionvalue_fromstring(
       char            *szStr,
       u8                *pInteger,
       u8                *pFraction,
       u32            *pu4bMove
)
{
   char    *szScan = szStr;
 
   /* Initialize output. */
   *pu4bMove = 0;
   *pInteger = 0;
   *pFraction = 0;
 
   /* Skip leading space. */
   while (*szScan != '\0' &&    (*szScan == ' ' || *szScan == '\t')) {
       ++szScan;
       ++(*pu4bMove);
   }
 
   if (*szScan < '0' || *szScan > '9')
       return false;
 
   /* Parse each digit. */
   do {
       (*pInteger) *= 10;
       *pInteger += (*szScan - '0');
 
       ++szScan;
       ++(*pu4bMove);
 
       if (*szScan == '.') {
           ++szScan;
           ++(*pu4bMove);
 
           if (*szScan < '0' || *szScan > '9')
               return false;
 
           *pFraction += (*szScan - '0') * 10;
           ++szScan;
           ++(*pu4bMove);
 
           if (*szScan >= '0' && *szScan <= '9') {
               *pFraction += *szScan - '0';
               ++szScan;
               ++(*pu4bMove);
           }
           return true;
       }
   } while (*szScan >= '0' && *szScan <= '9');
 
   return true;
}
 
bool hal_is_alpha(char ch_tmp)
{
   if ((ch_tmp >= 'a' && ch_tmp <= 'z') ||
       (ch_tmp >= 'A' && ch_tmp <= 'Z'))
       return true;
   else
       return false;
}
 
bool hal_ishexdigit(char ch_tmp)
{
   if ((ch_tmp >= '0' && ch_tmp <= '9') ||
       (ch_tmp >= 'a' && ch_tmp <= 'f') ||
       (ch_tmp >= 'A' && ch_tmp <= 'F'))
       return true;
   else
       return false;
}
 
bool hal_get_hexvalue_fromstring(
       char            *szStr,
       u32            *pu4bVal,
       u32            *pu4bMove
)
{
   char        *szScan = szStr;
 
   /* Check input parameter. */
   if (szStr == NULL || pu4bVal == NULL || pu4bMove == NULL) {
       PHL_INFO("GetHexValueFromString(): Invalid inpur argumetns! szStr: %p, pu4bVal: %p, pu4bMove: %p\n", szStr, pu4bVal, pu4bMove);
       return false;
   }
 
   /* Initialize output. */
   *pu4bMove = 0;
   *pu4bVal = 0;
 
   /* Skip leading space. */
   while (*szScan != '\0' &&
       (*szScan == ' ' || *szScan == '\t')) {
       szScan++;
       (*pu4bMove)++;
   }
 
   /* Skip leading '0x' or '0X'. */
   if (*szScan == '0' && (*(szScan + 1) == 'x' || *(szScan + 1) == 'X')) {
       szScan += 2;
       (*pu4bMove) += 2;
   }
 
   /* Check if szScan is now pointer to a character for hex digit, */
   /* if not, it means this is not a valid hex number. */
   if (!hal_ishexdigit(*szScan))
       return false;
 
   /* Parse each digit. */
   do {
       (*pu4bVal) <<= 4;
       *pu4bVal += hal_mapchar_tohexdigit(*szScan);
 
       szScan++;
       (*pu4bMove)++;
   } while (hal_ishexdigit(*szScan));
 
   return true;
}
 
bool hal_is_allspace_tab(
   char    *data,
   u8    size
)
{
   u8    cnt = 0, NumOfSpaceAndTab = 0;
 
   while (size > cnt) {
       if (data[cnt] == ' ' || data[cnt] == '\t' || data[cnt] == '\0')
           ++NumOfSpaceAndTab;
 
       ++cnt;
   }
 
   return size == NumOfSpaceAndTab;
}
 
u32 hal_mapchar_tohexdigit(
           char        chTmp
)
{
   if (chTmp >= '0' && chTmp <= '9')
       return chTmp - '0';
   else if (chTmp >= 'a' && chTmp <= 'f')
       return 10 + (chTmp - 'a');
   else if (chTmp >= 'A' && chTmp <= 'F')
       return 10 + (chTmp - 'A');
   else
       return 0;
}
 
 
bool hal_parse_fiedstring(char    *in_str, u32    *start, char    *out_str, char lqualifier, char rqualifier)
{
   u32    i = 0, j = 0;
   char    c = in_str[(*start)++];
 
   if (c != lqualifier)
       return false;
 
   i = (*start);
   c = in_str[(*start)++];
 
   while (c != rqualifier && c != '\0')
       c = in_str[(*start)++];
 
   if (c == '\0')
       return false;
 
   j = (*start) - 2;
   _os_strncpy((char *)out_str, (const char *)(in_str + i), j - i + 1);
 
   return true;
}
 
 
bool hal_get_u1bint_fromstr_indec(char    *str, u8    *pint)
{
   u16 i = 0;
   *pint = 0;
 
   while (str[i] != '\0') {
       if (str[i] >= '0' && str[i] <= '9') {
           *pint *= 10;
           *pint += (str[i] - '0');
       } else
           return false;
       ++i;
   }
 
   return true;
}
 
 
bool hal_get_s1bint_fromstr_indec(char    *str,    s8 *val)
{
   u8 negative = 0;
   u16 i = 0;
 
   *val = 0;
 
   while (str[i] != '\0') {
       if (i == 0 && (str[i] == '+' || str[i] == '-')) {
           if (str[i] == '-')
               negative = 1;
       } else if (str[i] >= '0' && str[i] <= '9') {
           *val *= 10;
           *val += (str[i] - '0');
       } else
           return false;
       ++i;
   }
 
   if (negative)
       *val = -*val;
 
   return true;
}