LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lib_ascii.c
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 CHARACTER OPERATIONS
26 *
27 * Filename : lib_ascii.c
28 * Version : V1.35.00
29 * Programmer(s) : BAN
30 * ITJ
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 * (2) (a) ECMA-6 '7-Bit coded Character Set' (6th edition), which corresponds to the
49 * 3rd edition of ISO 646, specifies several versions of a 7-bit character set :
50 *
51 * (1) THE GENERAL VERSION, which allows characters at 0x23 and 0x24 to be given a
52 * set alternate form and allows the characters 0x40, 0x5B, 0x5D, 0x60, 0x7B &
53 * 0x7D to be assigned a "unique graphic character" or to be declared as unused.
54 * All other characters are explicitly specified.
55 *
56 * (2) THE INTERNATIONAL REFERENCE VERSION, which explicitly specifies all characters
57 * in the 7-bit character set.
58 *
59 * (3) NATIONAL & APPLICATION-ORIENTED VERSIONS, which may be derived from the
60 * standard in specified ways.
61 *
62 * (b) The character set represented in this file reproduces the Internation Reference
63 * Version. This is identical to the 7-bit character set which occupies Unicode
64 * characters 0x0000 through 0x007F. The character names are taken from v5.0 of the
65 * Unicode specification, with certain abbreviations so that the resulting #define
66 * names will not violate ANSI C naming restriction :
67 *
68 * (1) For the Latin capital & lowercase letters, the name components 'LETTER_CAPITAL'
69 * & 'LETTER_SMALL' are replaced by 'UPPER' & 'LOWER', respectively.
70 *********************************************************************************************************
71 */
72 
73 
74 /*
75 *********************************************************************************************************
76 * INCLUDE FILES
77 *********************************************************************************************************
78 */
79 
80 #define LIB_ASCII_MODULE
81 #include <lib_ascii.h>
82 
83 
84 /*$PAGE*/
85 /*
86 *********************************************************************************************************
87 * LOCAL DEFINES
88 *********************************************************************************************************
89 */
90 
91 
92 /*
93 *********************************************************************************************************
94 * LOCAL CONSTANTS
95 *********************************************************************************************************
96 */
97 
98 
99 /*
100 *********************************************************************************************************
101 * LOCAL DATA TYPES
102 *********************************************************************************************************
103 */
104 
105 
106 /*
107 *********************************************************************************************************
108 * LOCAL TABLES
109 *********************************************************************************************************
110 */
111 
112 
113 /*
114 *********************************************************************************************************
115 * LOCAL GLOBAL VARIABLES
116 *********************************************************************************************************
117 */
118 
119 
120 /*
121 *********************************************************************************************************
122 * LOCAL FUNCTION PROTOTYPES
123 *********************************************************************************************************
124 */
125 
126 
127 /*
128 *********************************************************************************************************
129 * LOCAL CONFIGURATION ERRORS
130 *********************************************************************************************************
131 */
132 
133 
134 /*$PAGE*/
135 /*
136 *********************************************************************************************************
137 * ASCII_IsAlpha()
138 *
139 * Description : Determine whether a character is an alphabetic character.
140 *
141 * Argument(s) : c Character to examine.
142 *
143 * Return(s) : DEF_YES, if character is an alphabetic character.
144 *
145 * DEF_NO, if character is NOT an alphabetic character.
146 *
147 * Caller(s) : Application.
148 *
149 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.2.(2) states that "isalpha() returns true only for the
150 * characters for which isupper() or islower() is true".
151 *********************************************************************************************************
152 */
153 
155 {
156  CPU_BOOLEAN alpha;
157 
158 
159  alpha = ASCII_IS_ALPHA(c);
160 
161  return (alpha);
162 }
163 
164 
165 /*
166 *********************************************************************************************************
167 * ASCII_IsAlphaNum()
168 *
169 * Description : Determine whether a character is an alphanumeric character.
170 *
171 * Argument(s) : c Character to examine.
172 *
173 * Return(s) : DEF_YES, if character is an alphanumeric character.
174 *
175 * DEF_NO, if character is NOT an alphanumeric character.
176 *
177 * Caller(s) : Application.
178 *
179 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.1.(2) states that "isalnum() ... tests for any character
180 * for which isalpha() or isdigit() is true".
181 *********************************************************************************************************
182 */
183 
185 {
186  CPU_BOOLEAN alpha_num;
187 
188 
189  alpha_num = ASCII_IS_ALPHA_NUM(c);
190 
191  return (alpha_num);
192 }
193 
194 
195 /*$PAGE*/
196 /*
197 *********************************************************************************************************
198 * ASCII_IsLower()
199 *
200 * Description : Determine whether a character is a lowercase alphabetic character.
201 *
202 * Argument(s) : c Character to examine.
203 *
204 * Return(s) : DEF_YES, if character is a lowercase alphabetic character.
205 *
206 * DEF_NO, if character is NOT a lowercase alphabetic character.
207 *
208 * Caller(s) : Application.
209 *
210 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.7.(2) states that "islower() returns true only for
211 * the lowercase letters".
212 *********************************************************************************************************
213 */
214 
216 {
217  CPU_BOOLEAN lower;
218 
219 
220  lower = ASCII_IS_LOWER(c);
221 
222  return (lower);
223 }
224 
225 
226 /*
227 *********************************************************************************************************
228 * ASCII_IsUpper()
229 *
230 * Description : Determine whether a character is an uppercase alphabetic character.
231 *
232 * Argument(s) : c Character to examine.
233 *
234 * Return(s) : DEF_YES, if character is an uppercase alphabetic character.
235 *
236 * DEF_NO, if character is NOT an uppercase alphabetic character.
237 *
238 * Caller(s) : Application.
239 *
240 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.11.(2) states that "isupper() returns true only for
241 * the uppercase letters".
242 *********************************************************************************************************
243 */
244 
246 {
247  CPU_BOOLEAN upper;
248 
249 
250  upper = ASCII_IS_UPPER(c);
251 
252  return (upper);
253 }
254 
255 
256 /*$PAGE*/
257 /*
258 *********************************************************************************************************
259 * ASCII_IsDig()
260 *
261 * Description : Determine whether a character is a decimal-digit character.
262 *
263 * Argument(s) : c Character to examine.
264 *
265 * Return(s) : DEF_YES, if character is a decimal-digit character.
266 *
267 * DEF_NO, if character is NOT a decimal-digit character.
268 *
269 * Caller(s) : Application.
270 *
271 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.5.(2) states that "isdigit() ... tests for any
272 * decimal-digit character".
273 *********************************************************************************************************
274 */
275 
277 {
278  CPU_BOOLEAN dig;
279 
280 
281  dig = ASCII_IS_DIG(c);
282 
283  return (dig);
284 }
285 
286 
287 /*
288 *********************************************************************************************************
289 * ASCII_IsDigOct()
290 *
291 * Description : Determine whether a character is an octal-digit character.
292 *
293 * Argument(s) : c Character to examine.
294 *
295 * Return(s) : DEF_YES, if character is an octal-digit character.
296 *
297 * DEF_NO, if character is NOT an octal-digit character.
298 *
299 * Caller(s) : Application.
300 *
301 * Note(s) : none.
302 *********************************************************************************************************
303 */
304 
306 {
307  CPU_BOOLEAN dig_oct;
308 
309 
310  dig_oct = ASCII_IS_DIG_OCT(c);
311 
312  return (dig_oct);
313 }
314 
315 
316 /*
317 *********************************************************************************************************
318 * ASCII_IsDigHex()
319 *
320 * Description : Determine whether a character is a hexadecimal-digit character.
321 *
322 * Argument(s) : c Character to examine.
323 *
324 * Return(s) : DEF_YES, if character is a hexadecimal-digit character.
325 *
326 * DEF_NO, if character is NOT a hexadecimal-digit character.
327 *
328 * Caller(s) : Application.
329 *
330 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.12.(2) states that "isxdigit() ... tests for any
331 * hexadecimal-digit character".
332 *********************************************************************************************************
333 */
334 
336 {
337  CPU_BOOLEAN dig_hex;
338 
339 
340  dig_hex = ASCII_IS_DIG_HEX(c);
341 
342  return (dig_hex);
343 }
344 
345 
346 /*$PAGE*/
347 /*
348 *********************************************************************************************************
349 * ASCII_IsBlank()
350 *
351 * Description : Determine whether a character is a standard blank character.
352 *
353 * Argument(s) : c Character to examine.
354 *
355 * Return(s) : DEF_YES, if character is a standard blank character.
356 *
357 * DEF_NO, if character is NOT a standard blank character.
358 *
359 * Caller(s) : Application.
360 *
361 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.3.(2) states that "isblank() returns true only for
362 * the standard blank characters".
363 *
364 * (b) ISO/IEC 9899:TC2, Section 7.4.1.3.(2) defines "the standard blank characters" as
365 * the "space (' '), and horizontal tab ('\t')".
366 *********************************************************************************************************
367 */
368 
370 {
371  CPU_BOOLEAN blank;
372 
373 
374  blank = ASCII_IS_BLANK(c);
375 
376  return (blank);
377 }
378 
379 
380 /*
381 *********************************************************************************************************
382 * ASCII_IsSpace()
383 *
384 * Description : Determine whether a character is a white-space character.
385 *
386 * Argument(s) : c Character to examine.
387 *
388 * Return(s) : DEF_YES, if character is a white-space character.
389 *
390 * DEF_NO, if character is NOT a white-space character.
391 *
392 * Caller(s) : Application.
393 *
394 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.10.(2) states that "isspace() returns true only
395 * for the standard white-space characters".
396 *
397 * (b) ISO/IEC 9899:TC2, Section 7.4.1.10.(2) defines "the standard white-space characters"
398 * as the "space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),
399 * horizontal tab ('\t'), and vertical tab ('\v')".
400 *********************************************************************************************************
401 */
402 
404 {
405  CPU_BOOLEAN space;
406 
407 
408  space = ASCII_IS_SPACE(c);
409 
410  return (space);
411 }
412 
413 
414 /*$PAGE*/
415 /*
416 *********************************************************************************************************
417 * ASCII_IsPrint()
418 *
419 * Description : Determine whether a character is a printing character.
420 *
421 * Argument(s) : c Character to examine.
422 *
423 * Return(s) : DEF_YES, if character is a printing character.
424 *
425 * DEF_NO, if character is NOT a printing character.
426 *
427 * Caller(s) : Application.
428 *
429 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.8.(2) states that "isprint() ... tests for any
430 * printing character including space (' ')".
431 *
432 * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
433 * ASCII character set, the printing characters are those whose values lie from
434 * 0x20 (space) through 0x7E (tilde)".
435 *********************************************************************************************************
436 */
437 
439 {
440  CPU_BOOLEAN print;
441 
442 
443  print = ASCII_IS_PRINT(c);
444 
445  return (print);
446 }
447 
448 
449 /*
450 *********************************************************************************************************
451 * ASCII_IsGraph()
452 *
453 * Description : Determine whether a character is any printing character except a space character.
454 *
455 * Argument(s) : c Character to examine.
456 *
457 * Return(s) : DEF_YES, if character is a graphic character.
458 *
459 * DEF_NO, if character is NOT a graphic character.
460 *
461 * Caller(s) : Application.
462 *
463 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.6.(2) states that "isgraph() ... tests for any
464 * printing character except space (' ')".
465 *
466 * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
467 * ASCII character set, the printing characters are those whose values lie from
468 * 0x20 (space) through 0x7E (tilde)".
469 *********************************************************************************************************
470 */
471 
473 {
474  CPU_BOOLEAN graph;
475 
476 
477  graph = ASCII_IS_GRAPH(c);
478 
479  return (graph);
480 }
481 
482 
483 /*$PAGE*/
484 /*
485 *********************************************************************************************************
486 * ASCII_IsPunct()
487 *
488 * Description : Determine whether a character is a punctuation character.
489 *
490 * Argument(s) : c Character to examine.
491 *
492 * Return(s) : DEF_YES, if character is a punctuation character.
493 *
494 * DEF_NO, if character is NOT a punctuation character.
495 *
496 * Caller(s) : Application.
497 *
498 * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.9.(2) states that "ispunct() returns true for every
499 * printing character for which neither isspace() nor isalnum() is true".
500 *********************************************************************************************************
501 */
502 
504 {
505  CPU_BOOLEAN punct;
506 
507 
508  punct = ASCII_IS_PUNCT(c);
509 
510  return (punct);
511 }
512 
513 
514 /*
515 *********************************************************************************************************
516 * ASCII_IsCtrl()
517 *
518 * Description : Determine whether a character is a control character.
519 *
520 * Argument(s) : c Character to examine.
521 *
522 * Return(s) : DEF_YES, if character is a control character.
523 *
524 * DEF_NO, if character is NOT a control character.
525 *
526 * Caller(s) : Application.
527 *
528 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.4.(2) states that "iscntrl() ... tests for any
529 * control character".
530 *
531 * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
532 * ASCII character set, ... the control characters are those whose values lie from
533 * 0 (NUL) through 0x1F (US), and the character 0x7F (DEL)".
534 *********************************************************************************************************
535 */
536 
538 {
539  CPU_BOOLEAN ctrl;
540 
541 
542  ctrl = ASCII_IS_CTRL(c);
543 
544  return (ctrl);
545 }
546 
547 
548 /*$PAGE*/
549 /*
550 *********************************************************************************************************
551 * ASCII_ToLower()
552 *
553 * Description : Convert uppercase alphabetic character to its corresponding lowercase alphabetic character.
554 *
555 * Argument(s) : c Character to convert.
556 *
557 * Return(s) : Lowercase equivalent of 'c', if character 'c' is an uppercase character (see Note #1b1).
558 *
559 * Character 'c', otherwise (see Note #1b2).
560 *
561 * Caller(s) : Application.
562 *
563 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.2.1.(2) states that "tolower() ... converts an
564 * uppercase letter to a corresponding lowercase letter".
565 *
566 * (b) ISO/IEC 9899:TC2, Section 7.4.2.1.(3) states that :
567 *
568 * (1) (A) "if the argument is a character for which isupper() is true and there are
569 * one or more corresponding characters ... for which islower() is true," ...
570 * (B) "tolower() ... returns one of the corresponding characters;" ...
571 *
572 * (2) "otherwise, the argument is returned unchanged."
573 *********************************************************************************************************
574 */
575 
577 {
578  CPU_CHAR lower;
579 
580 
581  lower = ASCII_TO_LOWER(c);
582 
583  return (lower);
584 }
585 
586 
587 /*
588 *********************************************************************************************************
589 * ASCII_ToUpper()
590 *
591 * Description : Convert lowercase alphabetic character to its corresponding uppercase alphabetic character.
592 *
593 * Argument(s) : c Character to convert.
594 *
595 * Return(s) : Uppercase equivalent of 'c', if character 'c' is a lowercase character (see Note #1b1).
596 *
597 * Character 'c', otherwise (see Note #1b2).
598 *
599 * Caller(s) : Application.
600 *
601 * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.2.2.(2) states that "toupper() ... converts a
602 * lowercase letter to a corresponding uppercase letter".
603 *
604 * (b) ISO/IEC 9899:TC2, Section 7.4.2.2.(3) states that :
605 *
606 * (1) (A) "if the argument is a character for which islower() is true and there are
607 * one or more corresponding characters ... for which isupper() is true," ...
608 * (B) "toupper() ... returns one of the corresponding characters;" ...
609 *
610 * (2) "otherwise, the argument is returned unchanged."
611 *********************************************************************************************************
612 */
613 
615 {
616  CPU_CHAR upper;
617 
618 
619  upper = ASCII_TO_UPPER(c);
620 
621  return (upper);
622 }
623 
624 
625 /*$PAGE*/
626 /*
627 *********************************************************************************************************
628 * ASCII_Cmp()
629 *
630 * Description : Determine if two characters are identical (case-insensitive).
631 *
632 * Argument(s) : c1 First character.
633 *
634 * c2 Second character.
635 *
636 * Return(s) : DEF_YES, if the characters are identical.
637 *
638 * DEF_NO, if the characters are NOT identical.
639 *
640 * Caller(s) : Application.
641 *
642 * Note(s) : none.
643 *********************************************************************************************************
644 */
645 
647  CPU_CHAR c2)
648 {
649  CPU_CHAR c1_upper;
650  CPU_CHAR c2_upper;
651  CPU_BOOLEAN cmp;
652 
653 
654  c1_upper = ASCII_ToUpper(c1);
655  c2_upper = ASCII_ToUpper(c2);
656  cmp = (c1_upper == c2_upper) ? (DEF_YES) : (DEF_NO);
657 
658  return (cmp);
659 }
660