lib_str.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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 STRING MANAGEMENT
  28. *
  29. * Filename : lib_str.h
  30. * Version : V1.38.01
  31. * Programmer(s) : ITJ
  32. * JDH
  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. /*
  51. *********************************************************************************************************
  52. * MODULE
  53. *
  54. * Note(s) : (1) This string library header file is protected from multiple pre-processor inclusion through
  55. * use of the string library module present pre-processor macro definition.
  56. *********************************************************************************************************
  57. */
  58. #ifndef LIB_STR_MODULE_PRESENT /* See Note #1. */
  59. #define LIB_STR_MODULE_PRESENT
  60. /*
  61. *********************************************************************************************************
  62. * ASCII STRING CONFIGURATION DEFINES
  63. *
  64. * Note(s) : (1) Some ASCII string configuration #define's MUST be available PRIOR to including any
  65. * application configuration (see 'INCLUDE FILES Note #1a').
  66. *********************************************************************************************************
  67. */
  68. /*
  69. *********************************************************************************************************
  70. * STRING FLOATING POINT DEFINES
  71. *
  72. * Note(s) : (1) (a) (1) The maximum accuracy for 32-bit floating-point numbers :
  73. *
  74. *
  75. * Maximum Accuracy log [Internal-Base ^ (Number-Internal-Base-Digits)]
  76. * 32-bit Floating-point Number = -----------------------------------------------------
  77. * log [External-Base]
  78. *
  79. * log [2 ^ 24]
  80. * = --------------
  81. * log [10]
  82. *
  83. * < 7.225 Base-10 Digits
  84. *
  85. * where
  86. * Internal-Base Internal number base of floating-
  87. * point numbers (i.e. 2)
  88. * External-Base External number base of floating-
  89. * point numbers (i.e. 10)
  90. * Number-Internal-Base-Digits Number of internal number base
  91. * significant digits (i.e. 24)
  92. *
  93. * (2) Also, since some 32-bit floating-point calculations are converted to 32-bit
  94. * unsigned numbers, the maximum accuracy is limited to the maximum accuracy
  95. * for 32-bit unsigned numbers of 9 digits.
  96. *
  97. * (b) Some CPUs' &/or compilers' floating-point implementations MAY further reduce the
  98. * maximum accuracy.
  99. *********************************************************************************************************
  100. */
  101. #define LIB_STR_FP_MAX_NBR_DIG_SIG_MIN 1u
  102. #define LIB_STR_FP_MAX_NBR_DIG_SIG_MAX 9u /* See Note #1a2. */
  103. #define LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT 7u /* See Note #1a1. */
  104. /*
  105. *********************************************************************************************************
  106. * INCLUDE FILES
  107. *
  108. * Note(s) : (1) The custom library software files are located in the following directories :
  109. *
  110. * (a) \<Your Product Application>\lib_cfg.h
  111. *
  112. * (b) \<Custom Library Directory>\lib_*.*
  113. *
  114. * where
  115. * <Your Product Application> directory path for Your Product's Application
  116. * <Custom Library Directory> directory path for custom library software
  117. *
  118. * (2) CPU-configuration software files are located in the following directories :
  119. *
  120. * (a) \<CPU-Compiler Directory>\cpu_*.*
  121. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  122. *
  123. * where
  124. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  125. * <cpu> directory name for specific processor (CPU)
  126. * <compiler> directory name for specific compiler
  127. *
  128. * (3) Compiler MUST be configured to include as additional include path directories :
  129. *
  130. * (a) '\<Your Product Application>\' directory See Note #1a
  131. *
  132. * (b) '\<Custom Library Directory>\' directory See Note #1b
  133. *
  134. * (c) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  135. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  136. *
  137. * (4) NO compiler-supplied standard library functions SHOULD be used.
  138. *
  139. * #### The reference to standard library header files SHOULD be removed once all custom
  140. * library functions are implemented WITHOUT reference to ANY standard library function(s).
  141. *
  142. * See also 'STANDARD LIBRARY MACRO'S Note #1'.
  143. *********************************************************************************************************
  144. */
  145. #include <cpu.h>
  146. #include <lib_def.h>
  147. #include <lib_ascii.h>
  148. #include <lib_cfg.h>
  149. #if 0 /* See Note #4. */
  150. #include <stdio.h>
  151. #endif
  152. /*
  153. *********************************************************************************************************
  154. * EXTERNS
  155. *********************************************************************************************************
  156. */
  157. #ifdef LIB_STR_MODULE
  158. #define LIB_STR_EXT
  159. #else
  160. #define LIB_STR_EXT extern
  161. #endif
  162. /*
  163. *********************************************************************************************************
  164. * DEFAULT CONFIGURATION
  165. *********************************************************************************************************
  166. */
  167. /*
  168. *********************************************************************************************************
  169. * STRING FLOATING POINT CONFIGURATION
  170. *
  171. * Note(s) : (1) Configure LIB_STR_CFG_FP_EN to enable/disable floating point string function(s).
  172. *
  173. * (2) Configure LIB_STR_CFG_FP_MAX_NBR_DIG_SIG to configure the maximum number of significant
  174. * digits to calculate &/or display for floating point string function(s).
  175. *
  176. * See also 'STRING FLOATING POINT DEFINES Note #1'.
  177. *********************************************************************************************************
  178. */
  179. /* Configure floating point feature(s) [see Note #1] : */
  180. #ifndef LIB_STR_CFG_FP_EN
  181. #define LIB_STR_CFG_FP_EN DEF_DISABLED
  182. /* DEF_DISABLED Floating point functions DISABLED */
  183. /* DEF_ENABLED Floating point functions ENABLED */
  184. #endif
  185. /* Configure floating point feature(s)' number of ... */
  186. /* ... significant digits (see Note #2). */
  187. #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
  188. #define LIB_STR_CFG_FP_MAX_NBR_DIG_SIG LIB_STR_FP_MAX_NBR_DIG_SIG_DFLT
  189. #endif
  190. /*
  191. *********************************************************************************************************
  192. * DEFINES
  193. *********************************************************************************************************
  194. */
  195. #define STR_CR_LF "\r\n"
  196. #define STR_LF_CR "\n\r"
  197. #define STR_NEW_LINE STR_CR_LF
  198. #define STR_PARENT_PATH ".."
  199. #define STR_CR_LF_LEN (sizeof(STR_CR_LF) - 1)
  200. #define STR_LF_CR_LEN (sizeof(STR_LF_CR) - 1)
  201. #define STR_NEW_LINE_LEN (sizeof(STR_NEW_LINE) - 1)
  202. #define STR_PARENT_PATH_LEN (sizeof(STR_PARENT_PATH) - 1)
  203. /*
  204. *********************************************************************************************************
  205. * DATA TYPES
  206. *********************************************************************************************************
  207. */
  208. /*
  209. *********************************************************************************************************
  210. * GLOBAL VARIABLES
  211. *********************************************************************************************************
  212. */
  213. /*
  214. *********************************************************************************************************
  215. * MACRO'S
  216. *********************************************************************************************************
  217. */
  218. /*
  219. *********************************************************************************************************
  220. * STANDARD LIBRARY MACRO'S
  221. *
  222. * Note(s) : (1) NO compiler-supplied standard library functions SHOULD be used.
  223. *
  224. * #### The reference to standard memory functions SHOULD be removed once all custom library
  225. * functions are implemented WITHOUT reference to ANY standard library function(s).
  226. *
  227. * See also 'INCLUDE FILES Note #3'.
  228. *********************************************************************************************************
  229. */
  230. /* See Note #1. */
  231. #define Str_FmtPrint snprintf
  232. #define Str_FmtScan sscanf
  233. /*
  234. *********************************************************************************************************
  235. * FUNCTION PROTOTYPES
  236. *********************************************************************************************************
  237. */
  238. /* ------------------ STR LEN FNCTS ------------------ */
  239. CPU_SIZE_T Str_Len (const CPU_CHAR *pstr);
  240. CPU_SIZE_T Str_Len_N (const CPU_CHAR *pstr,
  241. CPU_SIZE_T len_max);
  242. /* ------------------ STR COPY FNCTS ------------------ */
  243. CPU_CHAR *Str_Copy ( CPU_CHAR *pstr_dest,
  244. const CPU_CHAR *pstr_src);
  245. CPU_CHAR *Str_Copy_N ( CPU_CHAR *pstr_dest,
  246. const CPU_CHAR *pstr_src,
  247. CPU_SIZE_T len_max);
  248. CPU_CHAR *Str_Cat ( CPU_CHAR *pstr_dest,
  249. const CPU_CHAR *pstr_cat);
  250. CPU_CHAR *Str_Cat_N ( CPU_CHAR *pstr_dest,
  251. const CPU_CHAR *pstr_cat,
  252. CPU_SIZE_T len_max);
  253. /* ------------------ STR CMP FNCTS ------------------ */
  254. CPU_INT16S Str_Cmp (const CPU_CHAR *p1_str,
  255. const CPU_CHAR *p2_str);
  256. CPU_INT16S Str_Cmp_N (const CPU_CHAR *p1_str,
  257. const CPU_CHAR *p2_str,
  258. CPU_SIZE_T len_max);
  259. CPU_INT16S Str_CmpIgnoreCase (const CPU_CHAR *p1_str,
  260. const CPU_CHAR *p2_str);
  261. CPU_INT16S Str_CmpIgnoreCase_N(const CPU_CHAR *p1_str,
  262. const CPU_CHAR *p2_str,
  263. CPU_SIZE_T len_max);
  264. /* ------------------ STR SRCH FNCTS ------------------ */
  265. CPU_CHAR *Str_Char (const CPU_CHAR *pstr,
  266. CPU_CHAR srch_char);
  267. CPU_CHAR *Str_Char_N (const CPU_CHAR *pstr,
  268. CPU_SIZE_T len_max,
  269. CPU_CHAR srch_char);
  270. CPU_CHAR *Str_Char_Last (const CPU_CHAR *pstr,
  271. CPU_CHAR srch_char);
  272. CPU_CHAR *Str_Char_Last_N (const CPU_CHAR *pstr,
  273. CPU_SIZE_T len_max,
  274. CPU_CHAR srch_char);
  275. CPU_CHAR *Str_Char_Replace ( CPU_CHAR *pstr,
  276. CPU_CHAR char_srch,
  277. CPU_CHAR char_replace);
  278. CPU_CHAR *Str_Char_Replace_N ( CPU_CHAR *pstr,
  279. CPU_CHAR char_srch,
  280. CPU_CHAR char_replace,
  281. CPU_SIZE_T len_max);
  282. CPU_CHAR *Str_Str (const CPU_CHAR *pstr,
  283. const CPU_CHAR *pstr_srch);
  284. CPU_CHAR *Str_Str_N (const CPU_CHAR *pstr,
  285. const CPU_CHAR *pstr_srch,
  286. CPU_SIZE_T len_max);
  287. /* ------------------ STR FMT FNCTS ------------------ */
  288. CPU_CHAR *Str_FmtNbr_Int32U ( CPU_INT32U nbr,
  289. CPU_INT08U nbr_dig,
  290. CPU_INT08U nbr_base,
  291. CPU_CHAR lead_char,
  292. CPU_BOOLEAN lower_case,
  293. CPU_BOOLEAN nul,
  294. CPU_CHAR *pstr);
  295. CPU_CHAR *Str_FmtNbr_Int32S ( CPU_INT32S nbr,
  296. CPU_INT08U nbr_dig,
  297. CPU_INT08U nbr_base,
  298. CPU_CHAR lead_char,
  299. CPU_BOOLEAN lower_case,
  300. CPU_BOOLEAN nul,
  301. CPU_CHAR *pstr);
  302. #if (LIB_STR_CFG_FP_EN == DEF_ENABLED)
  303. CPU_CHAR *Str_FmtNbr_32 ( CPU_FP32 nbr,
  304. CPU_INT08U nbr_dig,
  305. CPU_INT08U nbr_dp,
  306. CPU_CHAR lead_char,
  307. CPU_BOOLEAN nul,
  308. CPU_CHAR *pstr);
  309. #endif
  310. /* ----------------- STR PARSE FNCTS ------------------ */
  311. CPU_INT32U Str_ParseNbr_Int32U(const CPU_CHAR *pstr,
  312. CPU_CHAR **pstr_next,
  313. CPU_INT08U nbr_base);
  314. CPU_INT32S Str_ParseNbr_Int32S(const CPU_CHAR *pstr,
  315. CPU_CHAR **pstr_next,
  316. CPU_INT08U nbr_base);
  317. /*
  318. *********************************************************************************************************
  319. * CONFIGURATION ERRORS
  320. *********************************************************************************************************
  321. */
  322. #ifndef LIB_STR_CFG_FP_EN
  323. #error "LIB_STR_CFG_FP_EN not #define'd in 'lib_cfg.h'"
  324. #error " [MUST be DEF_DISABLED] "
  325. #error " [ || DEF_ENABLED ] "
  326. #elif ((LIB_STR_CFG_FP_EN != DEF_DISABLED) && \
  327. (LIB_STR_CFG_FP_EN != DEF_ENABLED ))
  328. #error "LIB_STR_CFG_FP_EN illegally #define'd in 'lib_cfg.h'"
  329. #error " [MUST be DEF_DISABLED] "
  330. #error " [ || DEF_ENABLED ] "
  331. #elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
  332. #ifndef LIB_STR_CFG_FP_MAX_NBR_DIG_SIG
  333. #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG not #define'd in 'lib_cfg.h' "
  334. #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
  335. #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
  336. #elif (DEF_CHK_VAL(LIB_STR_CFG_FP_MAX_NBR_DIG_SIG, \
  337. LIB_STR_FP_MAX_NBR_DIG_SIG_MIN, \
  338. LIB_STR_FP_MAX_NBR_DIG_SIG_MAX) != DEF_OK)
  339. #error "LIB_STR_CFG_FP_MAX_NBR_DIG_SIG illegally #define'd in 'lib_cfg.h' "
  340. #error " [MUST be >= LIB_STR_FP_MAX_NBR_DIG_SIG_MIN]"
  341. #error " [ && <= LIB_STR_FP_MAX_NBR_DIG_SIG_MAX]"
  342. #endif
  343. #endif
  344. /*
  345. *********************************************************************************************************
  346. * MODULE END
  347. *
  348. * Note(s) : (1) See 'lib_str.h MODULE'.
  349. *********************************************************************************************************
  350. */
  351. #endif /* End of lib str module include. */