File: utf16.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 (27 lines) | stat: -rw-r--r-- 675 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
#pragma once

#include "simdutf/encoding_types.h"

template <typename = void>
char16_t to_utf16(simdutf::endianness byte_order, char16_t chr) {
  if (!match_system(byte_order)) {
    return char16_t((uint16_t(chr) << 8) | (uint16_t(chr) >> 8));
  } else {
    return chr;
  }
}

template <typename = void> char16_t to_utf16be(char16_t chr) {
  return to_utf16(simdutf::endianness::BIG, chr);
}

template <typename = void> char16_t to_utf16le(char16_t chr) {
  return to_utf16(simdutf::endianness::LITTLE, chr);
}

template <typename = void>
void to_utf16le_inplace(char16_t *data, size_t size) {
  for (size_t i = 0; i < size; i++) {
    data[i] = to_utf16le(data[i]);
  }
}