Skip to content

Commit d9e7d3d

Browse files
committed
Add the right support functions for C++ encoding
1 parent 1993d84 commit d9e7d3d

File tree

35 files changed

+437
-267
lines changed

35 files changed

+437
-267
lines changed

Src/FastData.Cli.Tests/CommandOutputs/cpp_-s HashTable_Files_Strings.input.verified.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
class MyData final {
1313
struct e {
14-
std::u32string_view key;
14+
std::u16string_view key;
1515
int8_t next;
1616
uint64_t hash_code;
1717

18-
e(const std::u32string_view key, const int8_t next, const uint64_t hash_code)
18+
e(const std::u16string_view key, const int8_t next, const uint64_t hash_code)
1919
: key(key), next(next), hash_code(hash_code) {}
2020
};
2121

@@ -24,10 +24,10 @@ class MyData final {
2424
};
2525

2626
inline static const std::array<e, 2> entries = {
27-
e(U"test1", -1, 114), e(U"test2", 0, 114)
27+
e(u"test1", -1, 114), e(u"test2", 0, 114)
2828
};
2929

30-
static constexpr uint64_t get_hash(const std::u32string_view value) noexcept
30+
static constexpr uint64_t get_hash(const std::u16string_view value) noexcept
3131
{
3232
uint64_t hash = 352654597;
3333

@@ -39,7 +39,7 @@ class MyData final {
3939

4040
public:
4141
[[nodiscard]]
42-
static constexpr bool contains(const std::u32string_view key) noexcept {
42+
static constexpr bool contains(const std::u16string_view key) noexcept {
4343
if (key.length() != 5u)
4444
return false;
4545

Src/FastData.Cli.Tests/CommandOutputs/cpp_Files_Strings.input.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
class MyData final {
1313
public:
1414
[[nodiscard]]
15-
static constexpr bool contains(const std::u32string_view key) noexcept {
15+
static constexpr bool contains(const std::u16string_view key) noexcept {
1616
if (key.length() != 5u)
1717
return false;
1818

1919

20-
if (key == U"test1" || key == U"test2")
20+
if (key == u"test1" || key == u"test2")
2121
return true;
2222

2323
return false;

Src/FastData.Generator.CPlusPlus.TestHarness/CPlusPlusTestHarness.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private sealed class CPlusPlusRenderer : ITestRenderer
8787
public CPlusPlusRenderer(GeneratorSpec spec)
8888
{
8989
CPlusPlusLanguageDef langDef = new CPlusPlusLanguageDef();
90-
Encoding = spec.Flags.HasFlag(GeneratorFlags.AllAreASCII) ? GeneratorEncoding.ASCII : langDef.Encoding;
90+
Encoding = langDef.Encoding;
9191
_map = new TypeMap(langDef.TypeDefinitions, Encoding);
9292
}
9393

Src/FastData.Generator.CPlusPlus/Internal/Framework/CPlusPlusOutputWriter.cs

Lines changed: 249 additions & 79 deletions
Large diffs are not rendered by default.

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/IgnoreCaseSupport.verified.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@
77
#include <limits>
88
#include <string_view>
99

10-
static inline uint32_t to_lower_ascii(uint32_t c) noexcept
10+
static constexpr char16_t to_lower_ascii(char16_t c) noexcept
1111
{
12-
if (c - 'A' <= 'Z' - 'A')
13-
c |= 0x20u;
12+
if (c - u'A' <= u'Z' - u'A')
13+
c = static_cast<char16_t>(c | u'\x20');
1414

1515
return c;
1616
}
1717

18-
static inline bool case_insensitive_equals(std::u32string_view a, std::u32string_view b) noexcept
18+
static constexpr bool case_insensitive_equals(std::u16string_view a, std::u16string_view b) noexcept
1919
{
2020
if (a.size() != b.size())
2121
return false;
2222

2323
size_t len = a.size();
2424
for (size_t i = 0; i < len; i++)
2525
{
26-
if (to_lower_ascii(static_cast<uint32_t>(a[i])) != to_lower_ascii(static_cast<uint32_t>(b[i])))
26+
if (to_lower_ascii(a[i]) != to_lower_ascii(b[i]))
2727
return false;
2828
}
2929

3030
return true;
3131
}
3232

33-
static inline int case_insensitive_compare(std::u32string_view a, std::u32string_view b) noexcept
33+
static constexpr int case_insensitive_compare(std::u16string_view a, std::u16string_view b) noexcept
3434
{
3535
size_t a_len = a.size();
3636
size_t b_len = b.size();
3737
size_t len = a_len < b_len ? a_len : b_len;
3838

3939
for (size_t i = 0; i < len; i++)
4040
{
41-
uint32_t ca = to_lower_ascii(static_cast<uint32_t>(a[i]));
42-
uint32_t cb = to_lower_ascii(static_cast<uint32_t>(b[i]));
41+
auto ca = to_lower_ascii(a[i]);
42+
auto cb = to_lower_ascii(b[i]);
4343

4444
if (ca != cb)
4545
return ca < cb ? -1 : 1;
@@ -51,22 +51,22 @@ static inline int case_insensitive_compare(std::u32string_view a, std::u32string
5151
return a_len < b_len ? -1 : 1;
5252
}
5353

54-
static inline bool case_insensitive_starts_with(std::u32string_view value, std::u32string_view prefix) noexcept
54+
static constexpr bool case_insensitive_starts_with(std::u16string_view value, std::u16string_view prefix) noexcept
5555
{
5656
size_t prefix_len = prefix.size();
5757
if (prefix_len > value.size())
5858
return false;
5959

6060
for (size_t i = 0; i < prefix_len; i++)
6161
{
62-
if (to_lower_ascii(static_cast<uint32_t>(value[i])) != to_lower_ascii(static_cast<uint32_t>(prefix[i])))
62+
if (to_lower_ascii(value[i]) != to_lower_ascii(prefix[i]))
6363
return false;
6464
}
6565

6666
return true;
6767
}
6868

69-
static inline bool case_insensitive_ends_with(std::u32string_view value, std::u32string_view suffix) noexcept
69+
static constexpr bool case_insensitive_ends_with(std::u16string_view value, std::u16string_view suffix) noexcept
7070
{
7171
size_t suffix_len = suffix.size();
7272
size_t value_len = value.size();
@@ -78,20 +78,20 @@ static inline bool case_insensitive_ends_with(std::u32string_view value, std::u3
7878

7979
for (size_t i = 0; i < suffix_len; i++)
8080
{
81-
if (to_lower_ascii(static_cast<uint32_t>(value[offset + i])) != to_lower_ascii(static_cast<uint32_t>(suffix[i])))
81+
if (to_lower_ascii(value[offset + i]) != to_lower_ascii(suffix[i]))
8282
return false;
8383
}
8484

8585
return true;
8686
}
8787
class IgnoreCaseSupport final {
88-
static constexpr std::array<std::u32string_view, 3> keys = {
89-
U"Alpha", U"bravo", U"CHARLIE"
88+
static constexpr std::array<std::u16string_view, 3> keys = {
89+
u"Alpha", u"bravo", u"CHARLIE"
9090
};
9191

9292
public:
9393
[[nodiscard]]
94-
static constexpr bool contains(const std::u32string_view key) noexcept {
94+
static constexpr bool contains(const std::u16string_view key) noexcept {
9595
if (const size_t len = key.length(); len < 5u || len > 7u)
9696
return false;
9797

@@ -101,7 +101,7 @@ public:
101101
int32_t hi = 2;
102102
while (lo <= hi) {
103103
const int32_t mid = lo + ((hi - lo) >> 1);
104-
const std::u32string_view mid_key = keys[mid];
104+
const std::u16string_view mid_key = keys[mid];
105105
const int32_t order = case_insensitive_compare(mid_key, key);
106106

107107
if (order == 0)

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/KeyValueVectors_ArrayStructure_Int32_3_complex.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
struct Person {
1111
int32_t age;
12-
std::u32string_view name;
12+
std::u16string_view name;
1313
const Person* other;
1414

15-
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
15+
constexpr Person(const int32_t age, const std::u16string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1616
};
1717
class ArrayStructure_Int32_3_complex final {
1818
inline static const std::array<Person*, 3> values = {
19-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
19+
new Person(1, u"Bob", new Person(4, u"Anna", nullptr)), new Person(2, u"Billy", nullptr), new Person(3, u"Bibi", nullptr)
2020
};
2121
static constexpr std::array<int32_t, 3> keys = {
2222
1, 2, 3

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/KeyValueVectors_BinarySearchStructure_Int32_3_complex.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
struct Person {
1111
int32_t age;
12-
std::u32string_view name;
12+
std::u16string_view name;
1313
const Person* other;
1414

15-
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
15+
constexpr Person(const int32_t age, const std::u16string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1616
};
1717
class BinarySearchStructure_Int32_3_complex final {
1818
inline static const std::array<Person*, 3> values = {
19-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
19+
new Person(1, u"Bob", new Person(4, u"Anna", nullptr)), new Person(2, u"Billy", nullptr), new Person(3, u"Bibi", nullptr)
2020
};
2121
static constexpr std::array<int32_t, 3> keys = {
2222
1, 2, 3

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/KeyValueVectors_BitSetStructure_Int32_3_complex.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
struct Person {
1111
int32_t age;
12-
std::u32string_view name;
12+
std::u16string_view name;
1313
const Person* other;
1414

15-
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
15+
constexpr Person(const int32_t age, const std::u16string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1616
};
1717
class BitSetStructure_Int32_3_complex final {
1818
static constexpr std::array<uint64_t, 1> bitset = {
1919
7ull
2020
};
2121
inline static const std::array<Person*, 3> values = {
22-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
22+
new Person(1, u"Bob", new Person(4, u"Anna", nullptr)), new Person(2, u"Billy", nullptr), new Person(3, u"Bibi", nullptr)
2323
};
2424
public:
2525
[[nodiscard]]

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/KeyValueVectors_ConditionalStructure_Int32_3_complex.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
struct Person {
1111
int32_t age;
12-
std::u32string_view name;
12+
std::u16string_view name;
1313
const Person* other;
1414

15-
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
15+
constexpr Person(const int32_t age, const std::u16string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1616
};
1717
class ConditionalStructure_Int32_3_complex final {
1818
inline static const std::array<Person*, 3> values = {
19-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
19+
new Person(1, u"Bob", new Person(4, u"Anna", nullptr)), new Person(2, u"Billy", nullptr), new Person(3, u"Bibi", nullptr)
2020
};
2121
public:
2222
[[nodiscard]]

Src/FastData.TestHarness.Runner/Verify/Features/CPlusPlus/KeyValueVectors_HashTablePerfectStructure_Int32_3_complex.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
struct Person {
1111
int32_t age;
12-
std::u32string_view name;
12+
std::u16string_view name;
1313
const Person* other;
1414

15-
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
15+
constexpr Person(const int32_t age, const std::u16string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1616
};
1717
class HashTablePerfectStructure_Int32_3_complex final {
1818
struct e {
@@ -24,7 +24,7 @@ class HashTablePerfectStructure_Int32_3_complex final {
2424
: key(key), value(value) {}
2525
};
2626
inline static const std::array<e, 3> entries = {
27-
e(3, new Person(3, U"Bibi", nullptr)), e(1, new Person(1, U"Bob", new Person(4, U"Anna", nullptr))), e(2, new Person(2, U"Billy", nullptr))
27+
e(3, new Person(3, u"Bibi", nullptr)), e(1, new Person(1, u"Bob", new Person(4, u"Anna", nullptr))), e(2, new Person(2, u"Billy", nullptr))
2828
};
2929

3030
static constexpr uint64_t get_hash(const int32_t value) noexcept

0 commit comments

Comments
 (0)