ff_string.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * FreeRTOS+FAT V2.3.3
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * https://www.FreeRTOS.org
  23. * https://github.com/FreeRTOS
  24. *
  25. */
  26. /**
  27. * @file ff_string.c
  28. * @ingroup STRING
  29. *
  30. * @defgroup STRING FreeRTOS+FAT String Library
  31. * @brief Portable String Library for FreeRTOS+FAT
  32. *
  33. *
  34. **/
  35. #ifndef _FF_STRING_H_
  36. #define _FF_STRING_H_
  37. #include "FreeRTOSFATConfig.h"
  38. #include <string.h>
  39. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  40. #include <wchar.h>
  41. typedef wchar_t FF_T_WCHAR; /*/< Unicode UTF-16 Character type, for FreeRTOS+FAT when UNICODE is enabled. */
  42. #endif
  43. #if defined( _MSC_VER ) && ( _MSC_VER <= 1600 )
  44. #define FF_stricmp _stricmp
  45. #else
  46. #define FF_stricmp strcasecmp
  47. #endif
  48. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  49. void FF_tolower( FF_T_WCHAR * string,
  50. uint32_t strLen );
  51. void FF_toupper( FF_T_WCHAR * string,
  52. uint32_t strLen );
  53. BaseType_t FF_strmatch( const FF_T_WCHAR * str1,
  54. const FF_T_WCHAR * str2,
  55. BaseType_t len );
  56. FF_T_WCHAR * FF_strtok( const FF_T_WCHAR * string,
  57. FF_T_WCHAR * token,
  58. uint16_t * tokenNumber,
  59. BaseType_t * last,
  60. BaseType_t xLength );
  61. BaseType_t FF_wildcompare( const FF_T_WCHAR * pcWildCard,
  62. const FF_T_WCHAR * pszString );
  63. /* ASCII to UTF16 and UTF16 to ASCII routines. -- These are lossy routines, and are only for converting ASCII to UTF-16 */
  64. /* and the equivalent back to ASCII. Do not use them for international text. */
  65. void FF_cstrtowcs( FF_T_WCHAR * wcsDest,
  66. const char * szpSource );
  67. void FF_wcstocstr( char * szpDest,
  68. const FF_T_WCHAR * wcsSource );
  69. void FF_cstrntowcs( FF_T_WCHAR * wcsDest,
  70. const char * szpSource,
  71. uint32_t len );
  72. void FF_wcsntocstr( char * szpDest,
  73. const FF_T_WCHAR * wcsSource,
  74. uint32_t len );
  75. #else /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */
  76. void FF_tolower( char * string,
  77. uint32_t strLen );
  78. void FF_toupper( char * string,
  79. uint32_t strLen );
  80. BaseType_t FF_strmatch( const char * str1,
  81. const char * str2,
  82. BaseType_t len );
  83. char * FF_strtok( const char * string,
  84. char * token,
  85. uint16_t * tokenNumber,
  86. BaseType_t * last,
  87. BaseType_t xLength );
  88. BaseType_t FF_wildcompare( const char * pcWildCard,
  89. const char * pszString );
  90. #endif /* ffconfigUNICODE_UTF16_SUPPORT */
  91. /* UTF8 / UTF16 Transformation Functions. */
  92. #if ( ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) && ( WCHAR_MAX > 0xFFFF ) ) || ( ffconfigUNICODE_UTF8_SUPPORT != 0 )
  93. UBaseType_t FF_GetUtf16SequenceLen( uint16_t usLeadChar );
  94. #endif
  95. #if ( ffconfigUNICODE_UTF8_SUPPORT != 0 )
  96. int32_t FF_Utf8ctoUtf16c( uint16_t * utf16Dest,
  97. const uint8_t * utf8Source,
  98. uint32_t ulSize );
  99. int32_t FF_Utf16ctoUtf8c( uint8_t * utf8Dest,
  100. const uint16_t * utf16Source,
  101. uint32_t ulSize );
  102. #endif /* ffconfigUNICODE_UTF8_SUPPORT */
  103. /* UTF16 / UTF32 Transformation Functions. */
  104. #if ( ffconfigNOT_USED_FOR_NOW != 0 )
  105. int32_t FF_Utf16ctoUtf32c( uint32_t * utf32Dest,
  106. const uint16_t * utf16Source );
  107. #endif
  108. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) && ( WCHAR_MAX > 0xFFFF )
  109. int32_t FF_Utf32ctoUtf16c( uint16_t * utf16Dest,
  110. uint32_t utf32char,
  111. uint32_t ulSize );
  112. #endif
  113. /* String transformations. */
  114. int32_t FF_Utf32stoUtf8s( uint8_t * Utf8String,
  115. uint32_t * Utf32String );
  116. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  117. #define STRNCPY( target, src, maxlen ) wcsncpy( ( target ), ( src ), ( maxlen ) )
  118. #define STRLEN( string ) wcslen( ( string ) )
  119. #else
  120. #define STRNCPY( target, src, maxlen ) strncpy( ( target ), ( src ), ( maxlen ) );
  121. #define STRLEN( string ) strlen( ( string ) )
  122. #endif
  123. #endif /* ifndef _FF_STRING_H_ */