aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/simdutf/src/scalar/latin1.h
blob: 9e35add799d4d2f8703304de6cededbb990ac06e (plain)
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
#ifndef SIMDUTF_LATIN1_H
#define SIMDUTF_LATIN1_H

namespace simdutf {
namespace scalar {
namespace {
namespace latin1 {

inline size_t utf32_length_from_latin1(size_t len) {
  // We are not BOM aware.
  return len; // a utf32 unit will always represent 1 latin1 character
}

inline size_t utf8_length_from_latin1(const char *buf, size_t len) {
  const uint8_t *c = reinterpret_cast<const uint8_t *>(buf);
  size_t answer = 0;
  for (size_t i = 0; i < len; i++) {
    if ((c[i] >> 7)) {
      answer++;
    }
  }
  return answer + len;
}

inline size_t utf16_length_from_latin1(size_t len) { return len; }

} // namespace latin1
} // unnamed namespace
} // namespace scalar
} // namespace simdutf

#endif