|
Unicode Conversion |
Top Previous Next |
|
Various Unicode-related functions. Unit RVUni. function RVU_RawUnicodeToWideString(const s: String):WideString; function RVU_GetRawUnicode(const s: WideString):String; RVU_RawUnicodeToWideString converts "raw Unicode" string to WideString. RVU_GetRawUnicode converts WideString to "raw Unicode" string. type TRVCodePage = type cardinal; // defined in RVStyle unit function RVU_AnsiToUnicode(CodePage: TRVCodePage; const s: String): String; function RVU_UnicodeToAnsi(CodePage: TRVCodePage; const s: String): String; function RVU_AnsiToUTF8(CodePage: TRVCodePage; const s: String): String; RVU_AnsiToUnicode converts ANSI string (in the specified CodePage) to "raw Unicode" string. RVU_UnicodeToAnsi converts "raw Unicode" string to ANSI string (in the specified CodePage). RVU_AnsiToUTF8 converts ANSI string (in the specified CodePage) to UTF-8 string. type TRVUnicodeTestResult = (rvutNo, rvutYes, rvutProbably, rvutEmpty, rvutError); function RV_TestStreamUnicode(Stream: TStream): TRVUnicodeTestResult; function RV_TestFileUnicode(const FileName: String): TRVUnicodeTestResult; function RV_TestStringUnicode(const s: String): TRVUnicodeTestResult; These functions do very basic test of stream, file or string content to determine if they contain Unicode or ANSI text. Possible results:
First, these function check number of bytes in content. If it is odd, this is not Unicode text (rvutNo). Next, they check the first 2 bytes of text. If it is a Unicode byte order mark, this is very probably Unicode (rvutYes). Next, they check if there are 0-bytes in the first 500 bytes. If yes, it is not an ANSI (rvutYes), otherwise it may be any (rvutProbably). You can also use WinAPI function IsTextUnicode performing more advanced tests. See also: |