melder_textencoding.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _melder_textencoding_h_
  2. #define _melder_textencoding_h_
  3. /* melder_textencoding.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * Text encodings.
  22. */
  23. void Melder_textEncoding_prefs ();
  24. void Melder_setInputEncoding (kMelder_textInputEncoding encoding);
  25. kMelder_textInputEncoding Melder_getInputEncoding ();
  26. void Melder_setOutputEncoding (kMelder_textOutputEncoding encoding);
  27. kMelder_textOutputEncoding Melder_getOutputEncoding ();
  28. /*
  29. * Some other encodings. Although not used in the above set/get functions,
  30. * these constants should stay separate from the above encoding constants
  31. * because they occur in the same fields of struct MelderFile.
  32. */
  33. constexpr uint32 kMelder_textOutputEncoding_ASCII = 0x4153'4349;
  34. constexpr uint32 kMelder_textOutputEncoding_ISO_LATIN1 = 0x4C41'5401;
  35. constexpr uint32 kMelder_textOutputEncoding_FLAC = 0x464C'4143;
  36. bool Melder_isValidAscii (conststring32 string);
  37. bool Melder_str8IsValidUtf8 (const char *string);
  38. bool Melder_isEncodable (conststring32 string, int outputEncoding);
  39. extern char32 Melder_decodeMacRoman [256];
  40. extern char32 Melder_decodeWindowsLatin1 [256];
  41. /**
  42. Replace all bare returns (old Mac) or return-plus-linefeed sequences (Win) with bare linefeeds
  43. (generic: Unix and modern Mac).
  44. Return new length of string (equal to or less than old length).
  45. */
  46. integer Melder_killReturns_inplace (mutablestring32 text);
  47. integer Melder_killReturns_inplace (mutablestring8 text);
  48. size_t str32len_utf8 (conststring32 string, bool nativizeNewlines);
  49. size_t str32len_utf16 (conststring32 string, bool nativizeNewlines);
  50. extern "C" conststring32 Melder_peek8to32 (conststring8 string);
  51. void Melder_8to32_inplace (conststring8 source, mutablestring32 target, kMelder_textInputEncoding inputEncoding);
  52. // errors: Text is not valid UTF-8.
  53. autostring32 Melder_8to32 (conststring8 string, kMelder_textInputEncoding inputEncoding);
  54. // errors: Out of memory; Text is not valid UTF-8.
  55. autostring32 Melder_8to32 (conststring8 string);
  56. // errors: Out of memory; Text is not valid UTF-8.
  57. conststring32 Melder_peek16to32 (conststring16 text);
  58. autostring32 Melder_16to32 (conststring16 text);
  59. extern "C" conststring8 Melder_peek32to8 (conststring32 string);
  60. void Melder_32to8_inplace (conststring32 string, mutablestring8 utf8);
  61. autostring8 Melder_32to8 (conststring32 string);
  62. autostring16 Melder_32to16 (conststring32 string);
  63. // errors: Out of memory.
  64. conststring16 Melder_peek32to16 (conststring32 text, bool nativizeNewlines);
  65. extern "C" conststring16 Melder_peek32to16 (conststring32 string);
  66. #ifdef _WIN32
  67. inline static conststringW Melder_peek32toW (conststring32 string) { return (conststringW) Melder_peek32to16 (string); }
  68. autostringW Melder_32toW (conststring32 string);
  69. inline static conststring32 Melder_peekWto32 (conststringW string) { return Melder_peek16to32 ((conststring16) string); }
  70. inline static autostring32 Melder_Wto32 (conststringW string) { return Melder_16to32 ((conststring16) string); }
  71. #endif
  72. void Melder_str32To8bitFileRepresentation_inplace (conststring32 string, mutablestring8 utf8);
  73. void Melder_8bitFileRepresentationToStr32_inplace (conststring8 utf8, mutablestring32 string);
  74. const void * Melder_peek32toCfstring (conststring32 string);
  75. /* End of file melder_textencoding.h */
  76. #endif