lib_ascii.c 22 KB

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