Skip to content

Commit 36b2335

Browse files
authored
Merge pull request #8559 from xokdvium/dev/fix-char-traits-utf32
util: Replace std::basic_string<unsigned> with std::basic_string<char32_t>
2 parents 5ae1452 + 684bf42 commit 36b2335

7 files changed

+17
-23
lines changed

src/ansi-c/literals/convert_character_literal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ exprt convert_character_literal(
3232
PRECONDITION(src[1] == '\'');
3333
PRECONDITION(src[src.size() - 1] == '\'');
3434

35-
std::basic_string<unsigned int> value=
36-
unescape_wide_string(std::string(src, 2, src.size()-3));
35+
std::basic_string<char32_t> value =
36+
unescape_wide_string(std::string(src, 2, src.size() - 3));
3737
// the parser rejects empty character constants
3838
CHECK_RETURN(!value.empty());
3939

src/ansi-c/literals/convert_string_literal.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include "unescape_string.h"
2020

21-
std::basic_string<unsigned int> convert_one_string_literal(
22-
const std::string &src)
21+
std::basic_string<char32_t> convert_one_string_literal(const std::string &src)
2322
{
2423
PRECONDITION(src.size() >= 2);
2524

@@ -28,8 +27,8 @@ std::basic_string<unsigned int> convert_one_string_literal(
2827
PRECONDITION(src[src.size() - 1] == '"');
2928
PRECONDITION(src[2] == '"');
3029

31-
std::basic_string<unsigned int> value=
32-
unescape_wide_string(std::string(src, 3, src.size()-4));
30+
std::basic_string<char32_t> value =
31+
unescape_wide_string(std::string(src, 3, src.size() - 4));
3332

3433
// turn into utf-8
3534
const std::string utf8_value = utf32_native_endian_to_utf8(value);
@@ -57,7 +56,7 @@ std::basic_string<unsigned int> convert_one_string_literal(
5756
unescape_string(std::string(src, 1, src.size()-2));
5857

5958
// pad into wide string
60-
std::basic_string<unsigned int> value;
59+
std::basic_string<char32_t> value;
6160
value.resize(char_value.size());
6261
for(std::size_t i=0; i<char_value.size(); i++)
6362
value[i]=char_value[i];
@@ -72,7 +71,7 @@ exprt convert_string_literal(const std::string &src)
7271
// e.g., something like "asd" "xyz".
7372
// GCC allows "asd" L"xyz"!
7473

75-
std::basic_string<unsigned int> value;
74+
std::basic_string<char32_t> value;
7675

7776
char wide=0;
7877

@@ -101,8 +100,7 @@ exprt convert_string_literal(const std::string &src)
101100
INVARIANT(j < src.size(), "non-terminated string constant '" + src + "'");
102101

103102
std::string tmp_src=std::string(src, i, j-i+1);
104-
std::basic_string<unsigned int> tmp_value=
105-
convert_one_string_literal(tmp_src);
103+
std::basic_string<char32_t> tmp_value = convert_one_string_literal(tmp_src);
106104
value.append(tmp_value);
107105
i=j;
108106
}

src/ansi-c/literals/unescape_string.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ static void append_universal_char(
2020
unsigned int value,
2121
std::string &dest)
2222
{
23-
std::basic_string<unsigned int> value_str(1, value);
23+
std::basic_string<char32_t> value_str(1, value);
2424

2525
// turn into utf-8
2626
const std::string utf8_value = utf32_native_endian_to_utf8(value_str);
2727

2828
dest.append(utf8_value);
2929
}
3030

31-
static void append_universal_char(
32-
unsigned int value,
33-
std::basic_string<unsigned int> &dest)
31+
static void
32+
append_universal_char(unsigned int value, std::basic_string<char32_t> &dest)
3433
{
3534
dest.push_back(value);
3635
}
@@ -153,10 +152,9 @@ std::string unescape_string(const std::string &src)
153152
return unescape_string_templ<char>(src);
154153
}
155154

156-
std::basic_string<unsigned int> unescape_wide_string(
157-
const std::string &src)
155+
std::basic_string<char32_t> unescape_wide_string(const std::string &src)
158156
{
159-
return unescape_string_templ<unsigned int>(src);
157+
return unescape_string_templ<char32_t>(src);
160158
}
161159

162160
unsigned hex_to_unsigned(const char *hex, std::size_t digits)

src/ansi-c/literals/unescape_string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <string>
1616

1717
std::string unescape_string(const std::string &);
18-
std::basic_string<unsigned int> unescape_wide_string(const std::string &);
18+
std::basic_string<char32_t> unescape_wide_string(const std::string &);
1919

2020
unsigned hex_to_unsigned(const char *, std::size_t digits);
2121
unsigned octal_to_unsigned(const char *, std::size_t digits);

src/ansi-c/scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int make_identifier()
8989
for(; *p!=0 && digits>0; digits--, p++);
9090
p--; // go back for p++ later
9191

92-
std::basic_string<unsigned> utf32;
92+
std::basic_string<char32_t> utf32;
9393
utf32+=letter;
9494

9595
// turn into utf-8

src/util/unicode.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ static void utf8_append_code(unsigned int c, std::string &result)
133133

134134
/// \param s: UTF-32 encoded wide string
135135
/// \return utf8-encoded string with the same unicode characters as the input.
136-
std::string
137-
utf32_native_endian_to_utf8(const std::basic_string<unsigned int> &s)
136+
std::string utf32_native_endian_to_utf8(const std::basic_string<char32_t> &s)
138137
{
139138
std::string result;
140139

src/util/unicode.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ std::wstring widen(const std::string &s);
2828
# define widen_if_needed(s) (s)
2929
#endif
3030

31-
std::string
32-
utf32_native_endian_to_utf8(const std::basic_string<unsigned int> &s);
31+
std::string utf32_native_endian_to_utf8(const std::basic_string<char32_t> &s);
3332

3433
/// \param utf8_str: UTF-8 string
3534
/// \return UTF-32 encoding of the string

0 commit comments

Comments
 (0)