lib_ascii.c 23 KB

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