File: encode_utf32.h

package info (click to toggle)
simdutf 7.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,244 kB
  • sloc: cpp: 60,074; ansic: 14,226; python: 3,364; sh: 321; makefile: 12
file content (36 lines) | stat: -rw-r--r-- 696 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <cstdint>

namespace simdutf {
namespace tests {
namespace reference {
namespace utf32 {

// returns whether the value can be represented in the UTF-32
bool valid_value(uint32_t value) {

  if (value > 0x10FFFF)
    return false;

  if ((value >= 0xD800) && (value <= 0xDFFF))
    return false;

  return true;
}

// Encodes the value in UTF-32
// Returns 1 if the value can be encoded
// Returns 0 if the value cannot be encoded
template <typename CONSUMER> int encode(uint32_t value, CONSUMER consumer) {
  if (!valid_value(value))
    return 0;

  consumer(value);
  return 1;
}

} // namespace utf32
} // namespace reference
} // namespace tests
} // namespace simdutf