您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

833 行
46 KiB

  1. /*
  2. *********************************************************************************************************
  3. * uC/LIB
  4. * Custom Library Modules
  5. *
  6. * Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
  7. *
  8. * SPDX-License-Identifier: APACHE-2.0
  9. *
  10. * This software is subject to an open source license and is distributed by
  11. * Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  12. * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  13. *
  14. *********************************************************************************************************
  15. */
  16. /*
  17. *********************************************************************************************************
  18. *
  19. * ASCII CHARACTER OPERATIONS
  20. *
  21. * Filename : lib_ascii.h
  22. * Version : V1.39.01
  23. *********************************************************************************************************
  24. * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
  25. *
  26. * (a) ALL standard library functions are implemented in the custom library modules :
  27. *
  28. * (1) \<Custom Library Directory>\lib_*.*
  29. *
  30. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  31. *
  32. * where
  33. * <Custom Library Directory> directory path for custom library software
  34. * <cpu> directory name for specific processor (CPU)
  35. * <compiler> directory name for specific compiler
  36. *
  37. * (b) Product-specific library functions are implemented in individual products.
  38. *
  39. *
  40. * (2) (a) ECMA-6 '7-Bit coded Character Set' (6th edition), which corresponds to the
  41. * 3rd edition of ISO 646, specifies several versions of a 7-bit character set :
  42. *
  43. * (1) THE GENERAL VERSION, which allows characters at 0x23 and 0x24 to be given a
  44. * set alternate form and allows the characters 0x40, 0x5B, 0x5D, 0x60, 0x7B &
  45. * 0x7D to be assigned a "unique graphic character" or to be declared as unused.
  46. * All other characters are explicitly specified.
  47. *
  48. * (2) THE INTERNATIONAL REFERENCE VERSION, which explicitly specifies all characters
  49. * in the 7-bit character set.
  50. *
  51. * (3) NATIONAL & APPLICATION-ORIENTED VERSIONS, which may be derived from the
  52. * standard in specified ways.
  53. *
  54. * (b) The character set represented in this file reproduces the Internation Reference
  55. * Version. This is identical to the 7-bit character set which occupies Unicode
  56. * characters 0x0000 through 0x007F. The character names are taken from v5.0 of the
  57. * Unicode specification, with certain abbreviations so that the resulting #define
  58. * names will not violate ANSI C naming restriction :
  59. *
  60. * (1) For the Latin capital & lowercase letters, the name components 'LETTER_CAPITAL'
  61. * & 'LETTER_SMALL' are replaced by 'UPPER' & 'LOWER', respectively.
  62. *********************************************************************************************************
  63. */
  64. /*
  65. *********************************************************************************************************
  66. * MODULE
  67. *
  68. * Note(s) : (1) This ASCII library header file is protected from multiple pre-processor inclusion through
  69. * use of the ASCII library module present pre-processor macro definition.
  70. *********************************************************************************************************
  71. */
  72. #ifndef LIB_ASCII_MODULE_PRESENT /* See Note #1. */
  73. #define LIB_ASCII_MODULE_PRESENT
  74. /*
  75. *********************************************************************************************************
  76. * INCLUDE FILES
  77. *
  78. * Note(s) : (1) The custom library software files are located in the following directories :
  79. *
  80. * (a) \<Custom Library Directory>\lib_*.*
  81. *
  82. * where
  83. * <Custom Library Directory> directory path for custom library software
  84. *
  85. * (2) CPU-configuration software files are located in the following directories :
  86. *
  87. * (a) \<CPU-Compiler Directory>\cpu_*.*
  88. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  89. *
  90. * where
  91. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  92. * <cpu> directory name for specific processor (CPU)
  93. * <compiler> directory name for specific compiler
  94. *
  95. * (3) Compiler MUST be configured to include as additional include path directories :
  96. *
  97. * (a) '\<Custom Library Directory>\' directory See Note #1a
  98. *
  99. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  100. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  101. *
  102. * (4) NO compiler-supplied standard library functions SHOULD be used.
  103. *********************************************************************************************************
  104. */
  105. #include <cpu.h>
  106. #include <lib_def.h>
  107. /*
  108. *********************************************************************************************************
  109. * EXTERNS
  110. *********************************************************************************************************
  111. */
  112. #ifdef LIB_ASCII_MODULE
  113. #define LIB_ASCII_EXT
  114. #else
  115. #define LIB_ASCII_EXT extern
  116. #endif
  117. /*
  118. *********************************************************************************************************
  119. * DEFINES
  120. *********************************************************************************************************
  121. */
  122. /*
  123. *********************************************************************************************************
  124. * ASCII CHARACTER DEFINES
  125. *********************************************************************************************************
  126. */
  127. /* -------------------- C0 CONTROLS ------------------- */
  128. #define ASCII_CHAR_NULL 0x00 /* '\0' */
  129. #define ASCII_CHAR_START_OF_HEADING 0x01
  130. #define ASCII_CHAR_START_OF_TEXT 0x02
  131. #define ASCII_CHAR_END_OF_TEXT 0x03
  132. #define ASCII_CHAR_END_OF_TRANSMISSION 0x04
  133. #define ASCII_CHAR_ENQUIRY 0x05
  134. #define ASCII_CHAR_ACKNOWLEDGE 0x06
  135. #define ASCII_CHAR_BELL 0x07 /* '\a' */
  136. #define ASCII_CHAR_BACKSPACE 0x08 /* '\b' */
  137. #define ASCII_CHAR_CHARACTER_TABULATION 0x09 /* '\t' */
  138. #define ASCII_CHAR_LINE_FEED 0x0A /* '\n' */
  139. #define ASCII_CHAR_LINE_TABULATION 0x0B /* '\v' */
  140. #define ASCII_CHAR_FORM_FEED 0x0C /* '\f' */
  141. #define ASCII_CHAR_CARRIAGE_RETURN 0x0D /* '\r' */
  142. #define ASCII_CHAR_SHIFT_OUT 0x0E
  143. #define ASCII_CHAR_SHIFT_IN 0x0F
  144. #define ASCII_CHAR_DATA_LINK_ESCAPE 0x10
  145. #define ASCII_CHAR_DEVICE_CONTROL_ONE 0x11
  146. #define ASCII_CHAR_DEVICE_CONTROL_TWO 0x12
  147. #define ASCII_CHAR_DEVICE_CONTROL_THREE 0x13
  148. #define ASCII_CHAR_DEVICE_CONTROL_FOUR 0x14
  149. #define ASCII_CHAR_NEGATIVE_ACKNOWLEDGE 0x15
  150. #define ASCII_CHAR_SYNCHRONOUS_IDLE 0x16
  151. #define ASCII_CHAR_END_OF_TRANSMISSION_BLOCK 0x17
  152. #define ASCII_CHAR_CANCEL 0x18
  153. #define ASCII_CHAR_END_OF_MEDIUM 0x19
  154. #define ASCII_CHAR_SUBSITUTE 0x1A
  155. #define ASCII_CHAR_ESCAPE 0x1B
  156. #define ASCII_CHAR_INFO_SEPARATOR_FOUR 0x1C
  157. #define ASCII_CHAR_INFO_SEPARATOR_THREE 0x1D
  158. #define ASCII_CHAR_INFO_SEPARATOR_TWO 0x1E
  159. #define ASCII_CHAR_INFO_SEPARATOR_ONE 0x1F
  160. #define ASCII_CHAR_NUL ASCII_CHAR_NULL
  161. #define ASCII_CHAR_SOH ASCII_CHAR_START_OF_HEADING
  162. #define ASCII_CHAR_START_HEADING ASCII_CHAR_START_OF_HEADING
  163. #define ASCII_CHAR_STX ASCII_CHAR_START_OF_TEXT
  164. #define ASCII_CHAR_START_TEXT ASCII_CHAR_START_OF_TEXT
  165. #define ASCII_CHAR_ETX ASCII_CHAR_END_OF_TEXT
  166. #define ASCII_CHAR_END_TEXT ASCII_CHAR_END_OF_TEXT
  167. #define ASCII_CHAR_EOT ASCII_CHAR_END_OF_TRANSMISSION
  168. #define ASCII_CHAR_END_TRANSMISSION ASCII_CHAR_END_OF_TRANSMISSION
  169. #define ASCII_CHAR_ENQ ASCII_CHAR_ENQUIRY
  170. #define ASCII_CHAR_ACK ASCII_CHAR_ACKNOWLEDGE
  171. #define ASCII_CHAR_BEL ASCII_CHAR_BELL
  172. #define ASCII_CHAR_BS ASCII_CHAR_BACKSPACE
  173. #define ASCII_CHAR_HT ASCII_CHAR_CHARACTER_TABULATION
  174. #define ASCII_CHAR_TAB ASCII_CHAR_CHARACTER_TABULATION
  175. #define ASCII_CHAR_LF ASCII_CHAR_LINE_FEED
  176. #define ASCII_CHAR_VT ASCII_CHAR_LINE_TABULATION
  177. #define ASCII_CHAR_FF ASCII_CHAR_FORM_FEED
  178. #define ASCII_CHAR_CR ASCII_CHAR_CARRIAGE_RETURN
  179. #define ASCII_CHAR_SO ASCII_CHAR_SHIFT_OUT
  180. #define ASCII_CHAR_SI ASCII_CHAR_SHIFT_IN
  181. #define ASCII_CHAR_DLE ASCII_CHAR_DATA_LINK_ESCAPE
  182. #define ASCII_CHAR_DC1 ASCII_CHAR_DEVICE_CONTROL_ONE
  183. #define ASCII_CHAR_DC2 ASCII_CHAR_DEVICE_CONTROL_TWO
  184. #define ASCII_CHAR_DC3 ASCII_CHAR_DEVICE_CONTROL_THREE
  185. #define ASCII_CHAR_DC4 ASCII_CHAR_DEVICE_CONTROL_FOUR
  186. #define ASCII_CHAR_DEV_CTRL_ONE ASCII_CHAR_DEVICE_CONTROL_ONE
  187. #define ASCII_CHAR_DEV_CTRL_TWO ASCII_CHAR_DEVICE_CONTROL_TWO
  188. #define ASCII_CHAR_DEV_CTRL_THREE ASCII_CHAR_DEVICE_CONTROL_THREE
  189. #define ASCII_CHAR_DEV_CTRL_FOUR ASCII_CHAR_DEVICE_CONTROL_FOUR
  190. #define ASCII_CHAR_NAK ASCII_CHAR_NEGATIVE_ACKNOWLEDGE
  191. #define ASCII_CHAR_NEG_ACK ASCII_CHAR_NEGATIVE_ACKNOWLEDGE
  192. #define ASCII_CHAR_SYN ASCII_CHAR_SYNCHRONOUS_IDLE
  193. #define ASCII_CHAR_SYNC_IDLE ASCII_CHAR_SYNCHRONOUS_IDLE
  194. #define ASCII_CHAR_ETB ASCII_CHAR_END_OF_TRANSMISSION_BLOCK
  195. #define ASCII_CHAR_END_TRANSMISSION_BLK ASCII_CHAR_END_OF_TRANSMISSION_BLOCK
  196. #define ASCII_CHAR_CAN ASCII_CHAR_CANCEL
  197. #define ASCII_CHAR_EM ASCII_CHAR_END_OF_MEDIUM
  198. #define ASCII_CHAR_END_MEDIUM ASCII_CHAR_END_OF_MEDIUM
  199. #define ASCII_CHAR_SUB ASCII_CHAR_SUBSITUTE
  200. #define ASCII_CHAR_ESC ASCII_CHAR_ESCAPE
  201. #define ASCII_CHAR_IS1 ASCII_CHAR_INFO_SEPARATOR_ONE
  202. #define ASCII_CHAR_IS2 ASCII_CHAR_INFO_SEPARATOR_TWO
  203. #define ASCII_CHAR_IS3 ASCII_CHAR_INFO_SEPARATOR_THREE
  204. #define ASCII_CHAR_IS4 ASCII_CHAR_INFO_SEPARATOR_FOUR
  205. /* ------------ ASCII PUNCTUATION & SYMBOLS ----------- */
  206. #define ASCII_CHAR_SPACE 0x20 /* ' ' */
  207. #define ASCII_CHAR_EXCLAMATION_MARK 0x21 /* '!' */
  208. #define ASCII_CHAR_QUOTATION_MARK 0x22 /* '\"' */
  209. #define ASCII_CHAR_NUMBER_SIGN 0x23 /* '#' */
  210. #define ASCII_CHAR_DOLLAR_SIGN 0x24 /* '$' */
  211. #define ASCII_CHAR_PERCENTAGE_SIGN 0x25 /* '%' */
  212. #define ASCII_CHAR_AMPERSAND 0x26 /* '&' */
  213. #define ASCII_CHAR_APOSTROPHE 0x27 /* '\'' */
  214. #define ASCII_CHAR_LEFT_PARENTHESIS 0x28 /* '(' */
  215. #define ASCII_CHAR_RIGHT_PARENTHESIS 0x29 /* ')' */
  216. #define ASCII_CHAR_ASTERISK 0x2A /* '*' */
  217. #define ASCII_CHAR_PLUS_SIGN 0x2B /* '+' */
  218. #define ASCII_CHAR_COMMA 0x2C /* ',' */
  219. #define ASCII_CHAR_HYPHEN_MINUS 0x2D /* '-' */
  220. #define ASCII_CHAR_FULL_STOP 0x2E /* '.' */
  221. #define ASCII_CHAR_SOLIDUS 0x2F /* '/' */
  222. #define ASCII_CHAR_PAREN_LEFT ASCII_CHAR_LEFT_PARENTHESIS
  223. #define ASCII_CHAR_PAREN_RIGHT ASCII_CHAR_RIGHT_PARENTHESIS
  224. /* ------------------- ASCII DIGITS ------------------- */
  225. #define ASCII_CHAR_DIGIT_ZERO 0x30 /* '0' */
  226. #define ASCII_CHAR_DIGIT_ONE 0x31 /* '1' */
  227. #define ASCII_CHAR_DIGIT_TWO 0x32 /* '2' */
  228. #define ASCII_CHAR_DIGIT_THREE 0x33 /* '3' */
  229. #define ASCII_CHAR_DIGIT_FOUR 0x34 /* '4' */
  230. #define ASCII_CHAR_DIGIT_FIVE 0x35 /* '5' */
  231. #define ASCII_CHAR_DIGIT_SIX 0x36 /* '6' */
  232. #define ASCII_CHAR_DIGIT_SEVEN 0x37 /* '7' */
  233. #define ASCII_CHAR_DIGIT_EIGHT 0x38 /* '8' */
  234. #define ASCII_CHAR_DIGIT_NINE 0x39 /* '9' */
  235. #define ASCII_CHAR_DIG_ZERO ASCII_CHAR_DIGIT_ZERO
  236. #define ASCII_CHAR_DIG_ONE ASCII_CHAR_DIGIT_ONE
  237. #define ASCII_CHAR_DIG_TWO ASCII_CHAR_DIGIT_TWO
  238. #define ASCII_CHAR_DIG_THREE ASCII_CHAR_DIGIT_THREE
  239. #define ASCII_CHAR_DIG_FOUR ASCII_CHAR_DIGIT_FOUR
  240. #define ASCII_CHAR_DIG_FIVE ASCII_CHAR_DIGIT_FIVE
  241. #define ASCII_CHAR_DIG_SIX ASCII_CHAR_DIGIT_SIX
  242. #define ASCII_CHAR_DIG_SEVEN ASCII_CHAR_DIGIT_SEVEN
  243. #define ASCII_CHAR_DIG_EIGHT ASCII_CHAR_DIGIT_EIGHT
  244. #define ASCII_CHAR_DIG_NINE ASCII_CHAR_DIGIT_NINE
  245. /* ------------ ASCII PUNCTUATION & SYMBOLS ----------- */
  246. #define ASCII_CHAR_COLON 0x3A /* ':' */
  247. #define ASCII_CHAR_SEMICOLON 0x3B /* ';' */
  248. #define ASCII_CHAR_LESS_THAN_SIGN 0x3C /* '<' */
  249. #define ASCII_CHAR_EQUALS_SIGN 0x3D /* '=' */
  250. #define ASCII_CHAR_GREATER_THAN_SIGN 0x3E /* '>' */
  251. #define ASCII_CHAR_QUESTION_MARK 0x3F /* '\?' */
  252. #define ASCII_CHAR_COMMERCIAL_AT 0x40 /* '@' */
  253. #define ASCII_CHAR_AT_SIGN ASCII_CHAR_COMMERCIAL_AT
  254. /* ------------- UPPERCASE LATIN ALPHABET ------------- */
  255. #define ASCII_CHAR_LATIN_UPPER_A 0x41 /* 'A' */
  256. #define ASCII_CHAR_LATIN_UPPER_B 0x42 /* 'B' */
  257. #define ASCII_CHAR_LATIN_UPPER_C 0x43 /* 'C' */
  258. #define ASCII_CHAR_LATIN_UPPER_D 0x44 /* 'D' */
  259. #define ASCII_CHAR_LATIN_UPPER_E 0x45 /* 'E' */
  260. #define ASCII_CHAR_LATIN_UPPER_F 0x46 /* 'F' */
  261. #define ASCII_CHAR_LATIN_UPPER_G 0x47 /* 'G' */
  262. #define ASCII_CHAR_LATIN_UPPER_H 0x48 /* 'H' */
  263. #define ASCII_CHAR_LATIN_UPPER_I 0x49 /* 'I' */
  264. #define ASCII_CHAR_LATIN_UPPER_J 0x4A /* 'J' */
  265. #define ASCII_CHAR_LATIN_UPPER_K 0x4B /* 'K' */
  266. #define ASCII_CHAR_LATIN_UPPER_L 0x4C /* 'L' */
  267. #define ASCII_CHAR_LATIN_UPPER_M 0x4D /* 'M' */
  268. #define ASCII_CHAR_LATIN_UPPER_N 0x4E /* 'N' */
  269. #define ASCII_CHAR_LATIN_UPPER_O 0x4F /* 'O' */
  270. #define ASCII_CHAR_LATIN_UPPER_P 0x50 /* 'P' */
  271. #define ASCII_CHAR_LATIN_UPPER_Q 0x51 /* 'Q' */
  272. #define ASCII_CHAR_LATIN_UPPER_R 0x52 /* 'R' */
  273. #define ASCII_CHAR_LATIN_UPPER_S 0x53 /* 'S' */
  274. #define ASCII_CHAR_LATIN_UPPER_T 0x54 /* 'T' */
  275. #define ASCII_CHAR_LATIN_UPPER_U 0x55 /* 'U' */
  276. #define ASCII_CHAR_LATIN_UPPER_V 0x56 /* 'V' */
  277. #define ASCII_CHAR_LATIN_UPPER_W 0x57 /* 'W' */
  278. #define ASCII_CHAR_LATIN_UPPER_X 0x58 /* 'X' */
  279. #define ASCII_CHAR_LATIN_UPPER_Y 0x59 /* 'Y' */
  280. #define ASCII_CHAR_LATIN_UPPER_Z 0x5A /* 'Z' */
  281. /* ------------ ASCII PUNCTUATION & SYMBOLS ----------- */
  282. #define ASCII_CHAR_LEFT_SQUARE_BRACKET 0x5B /* '[' */
  283. #define ASCII_CHAR_REVERSE_SOLIDUS 0x5C /* '\\' */
  284. #define ASCII_CHAR_RIGHT_SQUARE_BRACKET 0x5D /* ']' */
  285. #define ASCII_CHAR_CIRCUMFLEX_ACCENT 0x5E /* '^' */
  286. #define ASCII_CHAR_LOW_LINE 0x5F /* '_' */
  287. #define ASCII_CHAR_GRAVE_ACCENT 0x60 /* '`' */
  288. #define ASCII_CHAR_BRACKET_SQUARE_LEFT ASCII_CHAR_LEFT_SQUARE_BRACKET
  289. #define ASCII_CHAR_BRACKET_SQUARE_RIGHT ASCII_CHAR_RIGHT_SQUARE_BRACKET
  290. /* ------------- LOWERCASE LATIN ALPHABET ------------- */
  291. #define ASCII_CHAR_LATIN_LOWER_A 0x61 /* 'a' */
  292. #define ASCII_CHAR_LATIN_LOWER_B 0x62 /* 'b' */
  293. #define ASCII_CHAR_LATIN_LOWER_C 0x63 /* 'c' */
  294. #define ASCII_CHAR_LATIN_LOWER_D 0x64 /* 'd' */
  295. #define ASCII_CHAR_LATIN_LOWER_E 0x65 /* 'e' */
  296. #define ASCII_CHAR_LATIN_LOWER_F 0x66 /* 'f' */
  297. #define ASCII_CHAR_LATIN_LOWER_G 0x67 /* 'g' */
  298. #define ASCII_CHAR_LATIN_LOWER_H 0x68 /* 'h' */
  299. #define ASCII_CHAR_LATIN_LOWER_I 0x69 /* 'i' */
  300. #define ASCII_CHAR_LATIN_LOWER_J 0x6A /* 'j' */
  301. #define ASCII_CHAR_LATIN_LOWER_K 0x6B /* 'k' */
  302. #define ASCII_CHAR_LATIN_LOWER_L 0x6C /* 'l' */
  303. #define ASCII_CHAR_LATIN_LOWER_M 0x6D /* 'm' */
  304. #define ASCII_CHAR_LATIN_LOWER_N 0x6E /* 'n' */
  305. #define ASCII_CHAR_LATIN_LOWER_O 0x6F /* 'o' */
  306. #define ASCII_CHAR_LATIN_LOWER_P 0x70 /* 'p' */
  307. #define ASCII_CHAR_LATIN_LOWER_Q 0x71 /* 'q' */
  308. #define ASCII_CHAR_LATIN_LOWER_R 0x72 /* 'r' */
  309. #define ASCII_CHAR_LATIN_LOWER_S 0x73 /* 's' */
  310. #define ASCII_CHAR_LATIN_LOWER_T 0x74 /* 't' */
  311. #define ASCII_CHAR_LATIN_LOWER_U 0x75 /* 'u' */
  312. #define ASCII_CHAR_LATIN_LOWER_V 0x76 /* 'v' */
  313. #define ASCII_CHAR_LATIN_LOWER_W 0x77 /* 'w' */
  314. #define ASCII_CHAR_LATIN_LOWER_X 0x78 /* 'x' */
  315. #define ASCII_CHAR_LATIN_LOWER_Y 0x79 /* 'y' */
  316. #define ASCII_CHAR_LATIN_LOWER_Z 0x7A /* 'z' */
  317. /* ------------ ASCII PUNCTUATION & SYMBOLS ----------- */
  318. #define ASCII_CHAR_LEFT_CURLY_BRACKET 0x7B /* '{' */
  319. #define ASCII_CHAR_VERTICAL_LINE 0x7C /* '|' */
  320. #define ASCII_CHAR_RIGHT_CURLY_BRACKET 0x7D /* '}' */
  321. #define ASCII_CHAR_TILDE 0x7E /* '~' */
  322. #define ASCII_CHAR_BRACKET_CURLY_LEFT ASCII_CHAR_LEFT_CURLY_BRACKET
  323. #define ASCII_CHAR_BRACKET_CURLY_RIGHT ASCII_CHAR_RIGHT_CURLY_BRACKET
  324. /* ---------------- CONTROL CHARACTERS ---------------- */
  325. #define ASCII_CHAR_DELETE 0x7F
  326. #define ASCII_CHAR_DEL ASCII_CHAR_DELETE
  327. /*
  328. *********************************************************************************************************
  329. * DATA TYPES
  330. *********************************************************************************************************
  331. */
  332. /*
  333. *********************************************************************************************************
  334. * GLOBAL VARIABLES
  335. *********************************************************************************************************
  336. */
  337. /*
  338. *********************************************************************************************************
  339. * MACRO'S
  340. *********************************************************************************************************
  341. */
  342. /*
  343. *********************************************************************************************************
  344. * ASCII CHARACTER CLASSIFICATION MACRO's
  345. *
  346. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.(1) states that "character classification functions ...
  347. * return nonzero (true) if and only if the value of the argument 'c' conforms to ... the
  348. * description of the function."
  349. *********************************************************************************************************
  350. */
  351. /*
  352. *********************************************************************************************************
  353. * ASCII_IS_DIG()
  354. *
  355. * Description : Determine whether a character is a decimal-digit character.
  356. *
  357. * Argument(s) : c Character to examine.
  358. *
  359. * Return(s) : DEF_YES, if character is a decimal-digit character.
  360. *
  361. * DEF_NO, if character is NOT a decimal-digit character.
  362. *
  363. * Caller(s) : Application.
  364. *
  365. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.5.(2) states that "isdigit() ... tests for any
  366. * decimal-digit character".
  367. *********************************************************************************************************
  368. */
  369. #define ASCII_IS_DIG(c) ((((c) >= ASCII_CHAR_DIG_ZERO) && ((c) <= ASCII_CHAR_DIG_NINE)) ? (DEF_YES) : (DEF_NO))
  370. /*
  371. *********************************************************************************************************
  372. * ASCII_IS_DIG_OCT()
  373. *
  374. * Description : Determine whether a character is an octal-digit character.
  375. *
  376. * Argument(s) : c Character to examine.
  377. *
  378. * Return(s) : DEF_YES, if character is an octal-digit character.
  379. *
  380. * DEF_NO, if character is NOT an octal-digit character.
  381. *
  382. * Caller(s) : Application.
  383. *
  384. * Note(s) : none.
  385. *********************************************************************************************************
  386. */
  387. #define ASCII_IS_DIG_OCT(c) ((((c) >= ASCII_CHAR_DIG_ZERO) && ((c) <= ASCII_CHAR_DIG_SEVEN)) ? (DEF_YES) : (DEF_NO))
  388. /*
  389. *********************************************************************************************************
  390. * ASCII_IS_DIG_HEX()
  391. *
  392. * Description : Determine whether a character is a hexadecimal-digit character.
  393. *
  394. * Argument(s) : c Character to examine.
  395. *
  396. * Return(s) : DEF_YES, if character is a hexadecimal-digit character.
  397. *
  398. * DEF_NO, if character is NOT a hexadecimal-digit character.
  399. *
  400. * Caller(s) : Application.
  401. *
  402. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.12.(2) states that "isxdigit() ... tests for any
  403. * hexadecimal-digit character".
  404. *********************************************************************************************************
  405. */
  406. #define ASCII_IS_DIG_HEX(c) (((((c) >= ASCII_CHAR_DIG_ZERO ) && ((c) <= ASCII_CHAR_DIG_NINE )) || \
  407. (((c) >= ASCII_CHAR_LATIN_UPPER_A) && ((c) <= ASCII_CHAR_LATIN_UPPER_F)) || \
  408. (((c) >= ASCII_CHAR_LATIN_LOWER_A) && ((c) <= ASCII_CHAR_LATIN_LOWER_F))) ? (DEF_YES) : (DEF_NO))
  409. /*
  410. *********************************************************************************************************
  411. * ASCII_IS_LOWER()
  412. *
  413. * Description : Determine whether a character is a lowercase alphabetic character.
  414. *
  415. * Argument(s) : c Character to examine.
  416. *
  417. * Return(s) : DEF_YES, if character is a lowercase alphabetic character.
  418. *
  419. * DEF_NO, if character is NOT a lowercase alphabetic character.
  420. *
  421. * Caller(s) : Application.
  422. *
  423. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.7.(2) states that "islower() returns true only for
  424. * the lowercase letters".
  425. *********************************************************************************************************
  426. */
  427. #define ASCII_IS_LOWER(c) ((((c) >= ASCII_CHAR_LATIN_LOWER_A) && ((c) <= ASCII_CHAR_LATIN_LOWER_Z)) ? (DEF_YES) : (DEF_NO))
  428. /*
  429. *********************************************************************************************************
  430. * ASCII_IS_UPPER()
  431. *
  432. * Description : Determine whether a character is an uppercase alphabetic character.
  433. *
  434. * Argument(s) : c Character to examine.
  435. *
  436. * Return(s) : DEF_YES, if character is an uppercase alphabetic character.
  437. *
  438. * DEF_NO, if character is NOT an uppercase alphabetic character.
  439. *
  440. * Caller(s) : Application.
  441. *
  442. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.11.(2) states that "isupper() returns true only for
  443. * the uppercase letters".
  444. *********************************************************************************************************
  445. */
  446. #define ASCII_IS_UPPER(c) ((((c) >= ASCII_CHAR_LATIN_UPPER_A) && ((c) <= ASCII_CHAR_LATIN_UPPER_Z)) ? (DEF_YES) : (DEF_NO))
  447. /*
  448. *********************************************************************************************************
  449. * ASCII_IS_ALPHA()
  450. *
  451. * Description : Determine whether a character is an alphabetic character.
  452. *
  453. * Argument(s) : c Character to examine.
  454. *
  455. * Return(s) : DEF_YES, if character is an alphabetic character.
  456. *
  457. * DEF_NO, if character is NOT an alphabetic character.
  458. *
  459. * Caller(s) : Application.
  460. *
  461. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.2.(2) states that "isalpha() returns true only for the
  462. * characters for which isupper() or islower() is true".
  463. *********************************************************************************************************
  464. */
  465. #define ASCII_IS_ALPHA(c) ((((ASCII_IS_UPPER(c)) == DEF_YES) || \
  466. ((ASCII_IS_LOWER(c)) == DEF_YES)) ? (DEF_YES) : (DEF_NO))
  467. /*
  468. *********************************************************************************************************
  469. * ASCII_IS_ALPHA_NUM()
  470. *
  471. * Description : Determine whether a character is an alphanumeric character.
  472. *
  473. * Argument(s) : c Character to examine.
  474. *
  475. * Return(s) : DEF_YES, if character is an alphanumeric character.
  476. *
  477. * DEF_NO, if character is NOT an alphanumeric character.
  478. *
  479. * Caller(s) : Application.
  480. *
  481. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.1.(2) states that "isalnum() ... tests for any character
  482. * for which isalpha() or isdigit() is true".
  483. *********************************************************************************************************
  484. */
  485. #define ASCII_IS_ALPHA_NUM(c) ((((ASCII_IS_ALPHA(c)) == DEF_YES) || \
  486. ((ASCII_IS_DIG (c)) == DEF_YES)) ? (DEF_YES) : (DEF_NO))
  487. /*
  488. *********************************************************************************************************
  489. * ASCII_IS_BLANK()
  490. *
  491. * Description : Determine whether a character is a standard blank character.
  492. *
  493. * Argument(s) : c Character to examine.
  494. *
  495. * Return(s) : DEF_YES, if character is a standard blank character.
  496. *
  497. * DEF_NO, if character is NOT a standard blank character.
  498. *
  499. * Caller(s) : Application.
  500. *
  501. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.3.(2) states that "isblank() returns true only for
  502. * the standard blank characters".
  503. *
  504. * (b) ISO/IEC 9899:TC2, Section 7.4.1.3.(2) defines "the standard blank characters" as
  505. * the "space (' '), and horizontal tab ('\t')".
  506. *********************************************************************************************************
  507. */
  508. #define ASCII_IS_BLANK(c) ((((c) == ASCII_CHAR_SPACE) || ((c) == ASCII_CHAR_HT)) ? (DEF_YES) : (DEF_NO))
  509. /*
  510. *********************************************************************************************************
  511. * ASCII_IS_SPACE()
  512. *
  513. * Description : Determine whether a character is a white-space character.
  514. *
  515. * Argument(s) : c Character to examine.
  516. *
  517. * Return(s) : DEF_YES, if character is a white-space character.
  518. *
  519. * DEF_NO, if character is NOT a white-space character.
  520. *
  521. * Caller(s) : Application.
  522. *
  523. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.10.(2) states that "isspace() returns true only
  524. * for the standard white-space characters".
  525. *
  526. * (b) ISO/IEC 9899:TC2, Section 7.4.1.10.(2) defines "the standard white-space characters"
  527. * as the "space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),
  528. * horizontal tab ('\t'), and vertical tab ('\v')".
  529. *********************************************************************************************************
  530. */
  531. #define ASCII_IS_SPACE(c) ((((c) == ASCII_CHAR_SPACE) || ((c) == ASCII_CHAR_CR) || \
  532. ((c) == ASCII_CHAR_LF ) || ((c) == ASCII_CHAR_FF) || \
  533. ((c) == ASCII_CHAR_HT ) || ((c) == ASCII_CHAR_VT)) ? (DEF_YES) : (DEF_NO))
  534. /*
  535. *********************************************************************************************************
  536. * ASCII_IS_PRINT()
  537. *
  538. * Description : Determine whether a character is a printing character.
  539. *
  540. * Argument(s) : c Character to examine.
  541. *
  542. * Return(s) : DEF_YES, if character is a printing character.
  543. *
  544. * DEF_NO, if character is NOT a printing character.
  545. *
  546. * Caller(s) : Application.
  547. *
  548. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.8.(2) states that "isprint() ... tests for any
  549. * printing character including space (' ')".
  550. *
  551. * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
  552. * ASCII character set, the printing characters are those whose values lie from
  553. * 0x20 (space) through 0x7E (tilde)".
  554. *********************************************************************************************************
  555. */
  556. #define ASCII_IS_PRINT(c) ((((c) >= ASCII_CHAR_SPACE) && ((c) <= ASCII_CHAR_TILDE)) ? (DEF_YES) : (DEF_NO))
  557. /*
  558. *********************************************************************************************************
  559. * ASCII_IS_GRAPH()
  560. *
  561. * Description : Determine whether a character is any printing character except a space character.
  562. *
  563. * Argument(s) : c Character to examine.
  564. *
  565. * Return(s) : DEF_YES, if character is a graphic character.
  566. *
  567. * DEF_NO, if character is NOT a graphic character.
  568. *
  569. * Caller(s) : Application.
  570. *
  571. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.6.(2) states that "isgraph() ... tests for any
  572. * printing character except space (' ')".
  573. *
  574. * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
  575. * ASCII character set, the printing characters are those whose values lie from
  576. * 0x20 (space) through 0x7E (tilde)".
  577. *********************************************************************************************************
  578. */
  579. #define ASCII_IS_GRAPH(c) ((((c) >= ASCII_CHAR_EXCLAMATION_MARK) && ((c) <= ASCII_CHAR_TILDE)) ? (DEF_YES) : (DEF_NO))
  580. /*
  581. *********************************************************************************************************
  582. * ASCII_IS_PUNCT()
  583. *
  584. * Description : Determine whether a character is a punctuation character.
  585. *
  586. * Argument(s) : c Character to examine.
  587. *
  588. * Return(s) : DEF_YES, if character is a punctuation character.
  589. *
  590. * DEF_NO, if character is NOT a punctuation character.
  591. *
  592. * Caller(s) : Application.
  593. *
  594. * Note(s) : (1) ISO/IEC 9899:TC2, Section 7.4.1.9.(2) states that "ispunct() returns true for every
  595. * printing character for which neither isspace() nor isalnum() is true".
  596. *********************************************************************************************************
  597. */
  598. #define ASCII_IS_PUNCT(c) (((((c) > ASCII_CHAR_SPACE) && ((c) < ASCII_CHAR_DIGIT_ZERO)) || \
  599. (((c) > ASCII_CHAR_DIGIT_NINE) && ((c) < ASCII_CHAR_LATIN_UPPER_A)) || \
  600. (((c) > ASCII_CHAR_LATIN_UPPER_Z) && ((c) < ASCII_CHAR_LATIN_LOWER_A)) || \
  601. (((c) > ASCII_CHAR_LATIN_LOWER_Z) && ((c) < ASCII_CHAR_DELETE))) ? (DEF_YES) : (DEF_NO))
  602. /*
  603. *********************************************************************************************************
  604. * ASCII_IS_CTRL()
  605. *
  606. * Description : Determine whether a character is a control character.
  607. *
  608. * Argument(s) : c Character to examine.
  609. *
  610. * Return(s) : DEF_YES, if character is a control character.
  611. *
  612. * DEF_NO, if character is NOT a control character.
  613. *
  614. * Caller(s) : Application.
  615. *
  616. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.1.4.(2) states that "iscntrl() ... tests for any
  617. * control character".
  618. *
  619. * (b) ISO/IEC 9899:TC2, Section 7.4.(3), Note 169, states that in "the seven-bit US
  620. * ASCII character set, ... the control characters are those whose values lie from
  621. * 0 (NUL) through 0x1F (US), and the character 0x7F (DEL)".
  622. *********************************************************************************************************
  623. */
  624. #define ASCII_IS_CTRL(c) (((((CPU_INT08S)(c) >= ASCII_CHAR_NULL ) && ((c) <= ASCII_CHAR_IS1)) || \
  625. ((c) == ASCII_CHAR_DEL)) ? (DEF_YES) : (DEF_NO))
  626. /*
  627. *********************************************************************************************************
  628. * ASCII CHARACTER CASE MAPPING MACRO's
  629. *********************************************************************************************************
  630. */
  631. /*
  632. *********************************************************************************************************
  633. * ASCII_TO_LOWER()
  634. *
  635. * Description : Convert uppercase alphabetic character to its corresponding lowercase alphabetic character.
  636. *
  637. * Argument(s) : c Character to convert.
  638. *
  639. * Return(s) : Lowercase equivalent of 'c', if character 'c' is an uppercase character (see Note #1b1).
  640. *
  641. * Character 'c', otherwise (see Note #1b2).
  642. *
  643. * Caller(s) : Application.
  644. *
  645. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.2.1.(2) states that "tolower() ... converts an
  646. * uppercase letter to a corresponding lowercase letter".
  647. *
  648. * (b) ISO/IEC 9899:TC2, Section 7.4.2.1.(3) states that :
  649. *
  650. * (1) (A) "if the argument is a character for which isupper() is true and there are
  651. * one or more corresponding characters ... for which islower() is true," ...
  652. * (B) "tolower() ... returns one of the corresponding characters;" ...
  653. *
  654. * (2) "otherwise, the argument is returned unchanged."
  655. *********************************************************************************************************
  656. */
  657. #define ASCII_TO_LOWER(c) (((ASCII_IS_UPPER(c)) == DEF_YES) ? ((c) + (ASCII_CHAR_LATIN_LOWER_A - ASCII_CHAR_LATIN_UPPER_A)) : (c))
  658. /*
  659. *********************************************************************************************************
  660. * ASCII_TO_UPPER()
  661. *
  662. * Description : Convert lowercase alphabetic character to its corresponding uppercase alphabetic character.
  663. *
  664. * Argument(s) : c Character to convert.
  665. *
  666. * Return(s) : Uppercase equivalent of 'c', if character 'c' is a lowercase character (see Note #1b1).
  667. *
  668. * Character 'c', otherwise (see Note #1b2).
  669. *
  670. * Caller(s) : Application.
  671. *
  672. * Note(s) : (1) (a) ISO/IEC 9899:TC2, Section 7.4.2.2.(2) states that "toupper() ... converts a
  673. * lowercase letter to a corresponding uppercase letter".
  674. *
  675. * (b) ISO/IEC 9899:TC2, Section 7.4.2.2.(3) states that :
  676. *
  677. * (1) (A) "if the argument is a character for which islower() is true and there are
  678. * one or more corresponding characters ... for which isupper() is true," ...
  679. * (B) "toupper() ... returns one of the corresponding characters;" ...
  680. *
  681. * (2) "otherwise, the argument is returned unchanged."
  682. *********************************************************************************************************
  683. */
  684. #define ASCII_TO_UPPER(c) (((ASCII_IS_LOWER(c)) == DEF_YES) ? ((c) - (ASCII_CHAR_LATIN_LOWER_A - ASCII_CHAR_LATIN_UPPER_A)) : (c))
  685. /*
  686. *********************************************************************************************************
  687. * FUNCTION PROTOTYPES
  688. *********************************************************************************************************
  689. */
  690. CPU_BOOLEAN ASCII_IsAlpha (CPU_CHAR c);
  691. CPU_BOOLEAN ASCII_IsAlphaNum(CPU_CHAR c);
  692. CPU_BOOLEAN ASCII_IsLower (CPU_CHAR c);
  693. CPU_BOOLEAN ASCII_IsUpper (CPU_CHAR c);
  694. CPU_BOOLEAN ASCII_IsDig (CPU_CHAR c);
  695. CPU_BOOLEAN ASCII_IsDigOct (CPU_CHAR c);
  696. CPU_BOOLEAN ASCII_IsDigHex (CPU_CHAR c);
  697. CPU_BOOLEAN ASCII_IsBlank (CPU_CHAR c);
  698. CPU_BOOLEAN ASCII_IsSpace (CPU_CHAR c);
  699. CPU_BOOLEAN ASCII_IsPrint (CPU_CHAR c);
  700. CPU_BOOLEAN ASCII_IsGraph (CPU_CHAR c);
  701. CPU_BOOLEAN ASCII_IsPunct (CPU_CHAR c);
  702. CPU_BOOLEAN ASCII_IsCtrl (CPU_CHAR c);
  703. CPU_CHAR ASCII_ToLower (CPU_CHAR c);
  704. CPU_CHAR ASCII_ToUpper (CPU_CHAR c);
  705. CPU_BOOLEAN ASCII_Cmp (CPU_CHAR c1,
  706. CPU_CHAR c2);
  707. /*
  708. *********************************************************************************************************
  709. * CONFIGURATION ERRORS
  710. *********************************************************************************************************
  711. */
  712. /*
  713. *********************************************************************************************************
  714. * MODULE END
  715. *
  716. * Note(s) : (1) See 'lib_ascii.h MODULE'.
  717. *********************************************************************************************************
  718. */
  719. #endif /* End of lib ascii module include. */