Coverage Report

Created: 2023-02-22 06:51

/src/hermes/lib/VM/StringRefUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
#include "hermes/VM/StringRefUtils.h"
9
10
#include "hermes/Support/UTF8.h"
11
12
#include "llvh/ADT/SmallString.h"
13
#include "llvh/Support/ConvertUTF.h"
14
#include "llvh/Support/raw_ostream.h"
15
16
namespace hermes {
17
namespace vm {
18
19
0
UTF16Ref createUTF16Ref(const char16_t *str) {
20
0
  return UTF16Ref(str, utf16_traits::length(str));
21
0
}
22
23
297
ASCIIRef createASCIIRef(const char *str) {
24
297
  return ASCIIRef(str, ascii_traits::length(str));
25
297
}
26
27
0
llvh::raw_ostream &operator<<(llvh::raw_ostream &OS, ASCIIRef asciiRef) {
28
0
  return OS << llvh::StringRef(asciiRef.data(), asciiRef.size());
29
0
}
30
31
/// Print the given UTF-16. We just assume UTF-8 output to avoid the increased
32
/// binary size of supporting multiple encodings.
33
67.1k
llvh::raw_ostream &operator<<(llvh::raw_ostream &OS, UTF16Ref u16ref) {
34
  // Note this assumes that the desired output encoding is UTF-8, which may
35
  // not be a valid assumption if outputting to a tty.
36
67.1k
  std::string narrowStr;
37
67.1k
  convertUTF16ToUTF8WithReplacements(narrowStr, u16ref);
38
67.1k
  return OS << narrowStr;
39
67.1k
}
40
41
} // namespace vm
42
} // namespace hermes