Commit 8bb5266
Replace deprecated std::wstring_convert with manual UTF-8 codec (k2-fsa#3215)
* Replace deprecated std::istrstream with std::istringstream
std::istrstream (from <strstream>) has been deprecated since C++98 and
produces -Wdeprecated-declarations warnings on GCC 14+ and Clang 18+.
Replace all 37 usages across 23 files with std::istringstream (from
<sstream>). The zero-copy property of istrstream is not needed at any
of these call sites — all source buffers outlive the stream and the
data sizes are small (symbol tables, lexicons, WAV chunks, FST rules).
For files that already include <sstream> (symbol-table.cc, lexicon.cc,
audio-tagging-label-file.cc, piper-phonemize-lexicon.cc,
offline-tts-character-frontend.cc, matcha-tts-lexicon.cc,
homophone-replacer.cc, melo-tts-lexicon.cc, character-lexicon.cc,
kokoro-multi-lang-lexicon.cc), the redundant <strstream> include is
simply removed.
* Replace deprecated std::wstring_convert with manual UTF-8 codec
std::wstring_convert and std::codecvt_utf8 were deprecated in C++17
and trigger -Wdeprecated-declarations warnings with GCC 11+. This
commit removes all uses across 6 files:
text-utils.cc – Rewrites Utf8ToUtf32(), Utf32ToUtf8(), ToWideString(),
and ToString() using manual RFC 3629 encoding/decoding.
Adds a new single-codepoint Utf32ToUtf8(char32_t) overload
(promoted from the local copy in matcha-tts-lexicon.cc).
text-utils.h – Declares the new Utf32ToUtf8(char32_t) overload.
kokoro-multi-lang-lexicon.cc – Replaces wstring_convert with calls to
Utf32ToUtf8() and Utf8ToUtf32() from text-utils.
piper-phonemize-lexicon.cc – Same replacement; adds text-utils.h include.
offline-tts-character-frontend.cc – Same replacement; adds text-utils.h
include.
matcha-tts-lexicon.cc – Removes the local static Utf32ToUtf8(char32_t)
that is now shared via text-utils.
The MSVC-only #include <codecvt> in onnx-utils.h is intentionally left
alone — it is guarded by #ifdef _MSC_VER, does not warn on Linux, and
may have hidden transitive dependencies on Windows.
Tested: full build with -DSHERPA_ONNX_ENABLE_TTS=ON on GCC 15.2 with
-Wdeprecated-declarations produces zero wstring_convert/codecvt warnings.
---------
Co-authored-by: John Suykerbuyk <bd770i@suykerbuyk.org>1 parent 0b76a7d commit 8bb5266
6 files changed
Lines changed: 252 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
377 | 376 | | |
378 | 377 | | |
379 | 378 | | |
380 | | - | |
381 | | - | |
382 | 379 | | |
383 | 380 | | |
384 | 381 | | |
385 | | - | |
| 382 | + | |
386 | 383 | | |
387 | 384 | | |
388 | 385 | | |
| |||
450 | 447 | | |
451 | 448 | | |
452 | 449 | | |
453 | | - | |
454 | 450 | | |
455 | 451 | | |
456 | | - | |
| 452 | + | |
457 | 453 | | |
458 | 454 | | |
459 | 455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 59 | | |
82 | 60 | | |
83 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | | - | |
| 63 | + | |
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
| |||
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
116 | | - | |
117 | | - | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
| |||
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
98 | | - | |
| 97 | + | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
0 commit comments