LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lib_str.h
Go to the documentation of this file.
1 /*
2 *********************************************************************************************************
3 * uC/LIB
4 * CUSTOM LIBRARY MODULES
5 *
6 * (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
7 *
8 * All rights reserved. Protected by international copyright laws.
9 *
10 * uC/LIB is provided in source form to registered licensees ONLY. It is
11 * illegal to distribute this source code to any third party unless you receive
12 * written permission by an authorized Micrium representative. Knowledge of
13 * the source code may NOT be used to develop a similar product.
14 *
15 * Please help us continue to provide the Embedded community with the finest
16 * software available. Your honesty is greatly appreciated.
17 *
18 * You can contact us at www.micrium.com.
19 *********************************************************************************************************
20 */
21 
22 /*
23 *********************************************************************************************************
24 *
25 * ASCII STRING MANAGEMENT
26 *
27 * Filename : lib_str.h
28 * Version : V1.35.00
29 * Programmer(s) : ITJ
30 * JDH
31 *********************************************************************************************************
32 * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
33 *
34 * (a) ALL standard library functions are implemented in the custom library modules :
35 *
36 * (1) <Custom Library Directory>\lib_*.*
37 *
38 * (2) <Custom Library Directory>\Ports<cpu><compiler>\lib*_a.*
39 *
40 * where
41 * <Custom Library Directory> directory path for custom library software
42 * <cpu> directory name for specific processor (CPU)
43 * <compiler> directory name for specific compiler
44 *
45 * (b) Product-specific library functions are implemented in individual products.
46 *********************************************************************************************************
47 */
48 
49 
50 /*
51 *********************************************************************************************************
52 * MODULE
53 *
54 * Note(s) : (1) This string library header file is protected from multiple pre-processor inclusion through
55 * use of the string library module present pre-processor macro definition.
56 *********************************************************************************************************
57 */
58 
59 #ifndef LIB_STR_MODULE_PRESENT /* See Note #1. */
60 #define LIB_STR_MODULE_PRESENT
61 
62 
63 /*$PAGE*/
64 /*
65 *********************************************************************************************************
66 * ASCII STRING CONFIGURATION DEFINES
67 *
68 * Note(s) : (1) Some ASCII string configuration #define's MUST be available PRIOR to including any
69 * application configuration (see 'INCLUDE FILES Note #1a').
70 *********************************************************************************************************
71 */
72 
73 /*
74 *********************************************************************************************************
75 * STRING FLOATING POINT DEFINES
76 *
77 * Note(s) : (1) (a) (1) The maximum accuracy for 32-bit floating-point numbers :
78 *
79 *
80 * Maximum Accuracy log [Internal-Base ^ (Number-Internal-Base-Digits)]
81 * 32-bit Floating-point Number = -----------------------------------------------------
82 * log [External-Base]
83 *
84 * log [2 ^ 24]
85 * = --------------
86 * log [10]
87 *
88 * < 7.225 Base-10 Digits
89 *
90 * where
91 * Internal-Base Internal number base of floating-
92 * point numbers (i.e. 2)
93 * External-Base External number base of floating-
94 * point numbers (i.e. 10)
95 * Number-Internal-Base-Digits Number of internal number base
96 * significant digits (i.e. 24)
97 *
98 * (2) Also, since some 32-bit floating-point calculations are converted to 32-bit
99 * unsigned numbers, the maximum accuracy is limited to the maximum accuracy
100 * for 32-bit unsigned numbers of 9 digits.
101 *
102 * (b) Some CPUs' &/or compilers' floating-point implementations MAY further reduce the
103 * maximum accuracy.
104 *********************************************************************************************************
105 */
106 
107 #define LIB_STR_FP_MAX_NBR_DIG_SIG_MIN 1
108 #define LIB_STR_FP_MAX_NBR_DIG_SIG_MAX 9 /* See Note #1a2. */
109 #define LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT 7 /* See Note #1a1. */
110 
111 
112 /*$PAGE*/
113 /*
114 *********************************************************************************************************
115 * INCLUDE FILES
116 *
117 * Note(s) : (1) The custom library software files are located in the following directories :
118 *
119 * (a) <Your Product Application>\app_cfg.h
120 *
121 * (b) <Custom Library Directory>\lib_*.*
122 *
123 * where
124 * <Your Product Application> directory path for Your Product's Application
125 * <Custom Library Directory> directory path for custom library software
126 *
127 * (2) CPU-configuration software files are located in the following directories :
128 *
129 * (a) <CPU-Compiler Directory>\cpu_*.*
130 * (b) <CPU-Compiler Directory><cpu><compiler>\cpu*.*
131 *
132 * where
133 * <CPU-Compiler Directory> directory path for common CPU-compiler software
134 * <cpu> directory name for specific processor (CPU)
135 * <compiler> directory name for specific compiler
136 *
137 * (3) Compiler MUST be configured to include as additional include path directories :
138 *
139 * (a) '<Your Product Application>\' directory See Note #1a
140 *
141 * (b) '<Custom Library Directory>\' directory See Note #1b
142 *
143 * (c) (1) '<CPU-Compiler Directory>\' directory See Note #2a
144 * (2) '<CPU-Compiler Directory><cpu><compiler>\' directory See Note #2b
145 *
146 * (4) NO compiler-supplied standard library functions SHOULD be used.
147 *
148 * #### The reference to standard library header files SHOULD be removed once all custom
149 * library functions are implemented WITHOUT reference to ANY standard library function(s).
150 *
151 * See also 'STANDARD LIBRARY MACRO'S Note #1'.
152 *********************************************************************************************************
153 */
154 
155 #include <cpu.h>
156 
157 #include <lib_def.h>
158 #include <lib_ascii.h>
159 
160 #include <app_cfg.h>
161 
162 #if 0 /* See Note #4. */
163 #include <stdio.h>
164 #endif
165 
166 
167 /*
168 *********************************************************************************************************
169 * EXTERNS
170 *********************************************************************************************************
171 */
172 
173 #ifdef LIB_STR_MODULE
174 #define LIB_STR_EXT
175 #else
176 #define LIB_STR_EXT extern
177 #endif
178 
179 
180 /*$PAGE*/
181 /*
182 *********************************************************************************************************
183 * DEFAULT CONFIGURATION
184 *********************************************************************************************************
185 */
186 
187 /*
188 *********************************************************************************************************
189 * STRING FLOATING POINT CONFIGURATION
190 *
191 * Note(s) : (1) Configure LIB_STR_CFG_FP_EN to enable/disable floating point string function(s).
192 *
193 * (2) Configure LIB_STR_CFG_FP_MAX_NBR_DIG_SIG to configure the maximum number of significant
194 * digits to calculate &/or display for floating point string function(s).
195 *
196 * See also 'STRING FLOATING POINT DEFINES Note #1'.
197 *********************************************************************************************************
198 */
199 
200  /* Configure floating point feature(s) [see Note #1] : */
201 #ifndef LIB_STR_CFG_FP_EN
202 #define LIB_STR_CFG_FP_EN DEF_DISABLED
203  /* DEF_DISABLED Floating point functions DISABLED */
204  /* DEF_ENABLED Floating point functions ENABLED */
205 #endif
206 
207  /* Configure floating point feature(s)' number of ... */
208  /* ... significant digits (see Note #2). */
209 #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
210 #define LIB_STR_CFG_FP_MAX_NBR_DIG_SIG LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT
211 #endif
212 
213 
214 /*
215 *********************************************************************************************************
216 * DEFINES
217 *********************************************************************************************************
218 */
219 
220 
221 /*
222 *********************************************************************************************************
223 * DATA TYPES
224 *********************************************************************************************************
225 */
226 
227 
228 /*
229 *********************************************************************************************************
230 * GLOBAL VARIABLES
231 *********************************************************************************************************
232 */
233 
234 
235 /*$PAGE*/
236 /*
237 *********************************************************************************************************
238 * MACRO'S
239 *********************************************************************************************************
240 */
241 
242 /*
243 *********************************************************************************************************
244 * STANDARD LIBRARY MACRO'S
245 *
246 * Note(s) : (1) NO compiler-supplied standard library functions SHOULD be used.
247 *
248 * #### The reference to standard memory functions SHOULD be removed once all custom library
249 * functions are implemented WITHOUT reference to ANY standard library function(s).
250 *
251 * See also 'INCLUDE FILES Note #3'.
252 *********************************************************************************************************
253 */
254 
255  /* See Note #1. */
256 #define Str_FmtPrint snprintf
257 #define Str_FmtScan sscanf
258 
259 
260 /*$PAGE*/
261 /*
262 *********************************************************************************************************
263 * FUNCTION PROTOTYPES
264 *********************************************************************************************************
265 */
266 
267  /* ------------------ STR LEN FNCTS ------------------ */
268 CPU_SIZE_T Str_Len (const CPU_CHAR *pstr);
269 
270 CPU_SIZE_T Str_Len_N (const CPU_CHAR *pstr,
271  CPU_SIZE_T len_max);
272 
273 
274  /* ------------------ STR COPY FNCTS ------------------ */
275 CPU_CHAR *Str_Copy ( CPU_CHAR *pstr_dest,
276  const CPU_CHAR *pstr_src);
277 
278 CPU_CHAR *Str_Copy_N ( CPU_CHAR *pstr_dest,
279  const CPU_CHAR *pstr_src,
280  CPU_SIZE_T len_max);
281 
282 
283 CPU_CHAR *Str_Cat ( CPU_CHAR *pstr_dest,
284  const CPU_CHAR *pstr_cat);
285 
286 CPU_CHAR *Str_Cat_N ( CPU_CHAR *pstr_dest,
287  const CPU_CHAR *pstr_cat,
288  CPU_SIZE_T len_max);
289 
290 
291  /* ------------------ STR CMP FNCTS ------------------ */
292 CPU_INT16S Str_Cmp (const CPU_CHAR *p1_str,
293  const CPU_CHAR *p2_str);
294 
295 CPU_INT16S Str_Cmp_N (const CPU_CHAR *p1_str,
296  const CPU_CHAR *p2_str,
297  CPU_SIZE_T len_max);
298 
299 CPU_INT16S Str_CmpIgnoreCase (const CPU_CHAR *p1_str,
300  const CPU_CHAR *p2_str);
301 
303  const CPU_CHAR *p2_str,
304  CPU_SIZE_T len_max);
305 
306 
307  /* ------------------ STR SRCH FNCTS ------------------ */
308 CPU_CHAR *Str_Char (const CPU_CHAR *pstr,
309  CPU_CHAR srch_char);
310 
311 CPU_CHAR *Str_Char_N (const CPU_CHAR *pstr,
312  CPU_SIZE_T len_max,
313  CPU_CHAR srch_char);
314 
315 CPU_CHAR *Str_Char_Last (const CPU_CHAR *pstr,
316  CPU_CHAR srch_char);
317 
318 CPU_CHAR *Str_Char_Last_N (const CPU_CHAR *pstr,
319  CPU_SIZE_T len_max,
320  CPU_CHAR srch_char);
321 
322 
323 CPU_CHAR *Str_Str (const CPU_CHAR *pstr,
324  const CPU_CHAR *pstr_srch);
325 
326 CPU_CHAR *Str_Str_N (const CPU_CHAR *pstr,
327  const CPU_CHAR *pstr_srch,
328  CPU_SIZE_T len_max);
329 
330 
331 /*$PAGE*/
332  /* ------------------ STR FMT FNCTS ------------------ */
334  CPU_INT08U nbr_dig,
335  CPU_INT08U nbr_base,
336  CPU_CHAR lead_char,
337  CPU_BOOLEAN lower_case,
338  CPU_BOOLEAN nul,
339  CPU_CHAR *pstr);
340 
342  CPU_INT08U nbr_dig,
343  CPU_INT08U nbr_base,
344  CPU_CHAR lead_char,
345  CPU_BOOLEAN lower_case,
346  CPU_BOOLEAN nul,
347  CPU_CHAR *pstr);
348 
349 #if (LIB_STR_CFG_FP_EN == DEF_ENABLED)
351  CPU_INT08U nbr_dig,
352  CPU_INT08U nbr_dp,
353  CPU_CHAR lead_char,
354  CPU_BOOLEAN nul,
355  CPU_CHAR *pstr);
356 #endif
357 
358 
359  /* ----------------- STR PARSE FNCTS ------------------ */
361  CPU_CHAR **pstr_next,
362  CPU_INT08U nbr_base);
363 
365  CPU_CHAR **pstr_next,
366  CPU_INT08U nbr_base);
367 
368 
369 /*$PAGE*/
370 /*
371 *********************************************************************************************************
372 * CONFIGURATION ERRORS
373 *********************************************************************************************************
374 */
375 
376 #ifndef LIB_STR_CFG_FP_EN
377 #error "LIB_STR_CFG_FP_EN not #define'd in 'app_cfg.h'"
378 #error " [MUST be DEF_DISABLED] "
379 #error " [ || DEF_ENABLED ] "
380 
381 #elif ((LIB_STR_CFG_FP_EN != DEF_DISABLED) && \
382  (LIB_STR_CFG_FP_EN != DEF_ENABLED ))
383 #error "LIB_STR_CFG_FP_EN illegally #define'd in 'app_cfg.h'"
384 #error " [MUST be DEF_DISABLED] "
385 #error " [ || DEF_ENABLED ] "
386 
387 
388 #elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
389 
390 #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
391 #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG not #define'd in 'app_cfg.h' "
392 #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
393 #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
394 
395 #elif (DEF_CHK_VAL(LIB_STR_CFG_FP_MAX_NBR_DIG_SIG, \
396  LIB_STR_FP_MAX_NBR_DIG_SIG_MIN, \
397  LIB_STR_FP_MAX_NBR_DIG_SIG_MAX) != DEF_OK)
398 #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG illegally #define'd in 'app_cfg.h' "
399 #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
400 #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
401 #endif
402 
403 #endif
404 
405 
406 /*
407 *********************************************************************************************************
408 * MODULE END
409 *********************************************************************************************************
410 */
411 
412 #endif /* End of lib str module include. */
413