GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_i18n.h Lines: 15 18 83.3 %
Date: 2020-08-17 22:13:26 Branches: 2 2 100.0 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#ifndef SRC_NODE_I18N_H_
23
#define SRC_NODE_I18N_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#if defined(NODE_HAVE_I18N_SUPPORT)
28
29
#include "base_object.h"
30
#include "env.h"
31
#include "util.h"
32
#include "v8.h"
33
34
#include <unicode/ucnv.h>
35
36
#include <string>
37
38
namespace node {
39
namespace i18n {
40
41
bool InitializeICUDirectory(const std::string& path);
42
43
enum idna_mode {
44
  // Default mode for maximum compatibility.
45
  IDNA_DEFAULT,
46
  // Ignore all errors in IDNA conversion, if possible.
47
  IDNA_LENIENT,
48
  // Enforce STD3 rules (UseSTD3ASCIIRules) and DNS length restrictions
49
  // (VerifyDnsLength). Corresponds to `beStrict` flag in the "domain to ASCII"
50
  // algorithm.
51
  IDNA_STRICT
52
};
53
54
// Implements the WHATWG URL Standard "domain to ASCII" algorithm.
55
// https://url.spec.whatwg.org/#concept-domain-to-ascii
56
int32_t ToASCII(MaybeStackBuffer<char>* buf,
57
                const char* input,
58
                size_t length,
59
                enum idna_mode mode = IDNA_DEFAULT);
60
61
// Implements the WHATWG URL Standard "domain to Unicode" algorithm.
62
// https://url.spec.whatwg.org/#concept-domain-to-unicode
63
int32_t ToUnicode(MaybeStackBuffer<char>* buf,
64
                  const char* input,
65
                  size_t length);
66
67
struct ConverterDeleter {
68
10872
  void operator()(UConverter* pointer) const { ucnv_close(pointer); }
69
};
70
using ConverterPointer = std::unique_ptr<UConverter, ConverterDeleter>;
71
72
10871
class Converter {
73
 public:
74
  explicit Converter(const char* name, const char* sub = nullptr);
75
  explicit Converter(UConverter* converter, const char* sub = nullptr);
76
77
7847
  UConverter* conv() const { return conv_.get(); }
78
79
  size_t max_char_size() const;
80
  size_t min_char_size() const;
81
  void reset();
82
  void set_subst_chars(const char* sub = nullptr);
83
84
 private:
85
  ConverterPointer conv_;
86
};
87
88
21726
class ConverterObject : public BaseObject, Converter {
89
 public:
90
  enum ConverterFlags {
91
    CONVERTER_FLAGS_FLUSH      = 0x1,
92
    CONVERTER_FLAGS_FATAL      = 0x2,
93
    CONVERTER_FLAGS_IGNORE_BOM = 0x4,
94
    CONVERTER_FLAGS_UNICODE    = 0x8,
95
    CONVERTER_FLAGS_BOM_SEEN   = 0x10,
96
  };
97
98
  static void Create(const v8::FunctionCallbackInfo<v8::Value>& args);
99
  static void Decode(const v8::FunctionCallbackInfo<v8::Value>& args);
100
  static void Has(const v8::FunctionCallbackInfo<v8::Value>& args);
101
102
  SET_NO_MEMORY_INFO()
103
  SET_MEMORY_INFO_NAME(ConverterObject)
104
  SET_SELF_SIZE(ConverterObject)
105
106
 protected:
107
  ConverterObject(Environment* env,
108
                  v8::Local<v8::Object> wrap,
109
                  UConverter* converter,
110
                  int flags,
111
                  const char* sub = nullptr);
112
113
7791
  void set_bom_seen(bool seen) {
114
7791
    if (seen)
115
370
      flags_ |= CONVERTER_FLAGS_BOM_SEEN;
116
    else
117
7421
      flags_ &= ~CONVERTER_FLAGS_BOM_SEEN;
118
7791
  }
119
120
650
  bool bom_seen() const {
121
650
    return (flags_ & CONVERTER_FLAGS_BOM_SEEN) == CONVERTER_FLAGS_BOM_SEEN;
122
  }
123
124
7468
  bool unicode() const {
125
7468
    return (flags_ & CONVERTER_FLAGS_UNICODE) == CONVERTER_FLAGS_UNICODE;
126
  }
127
128
664
  bool ignore_bom() const {
129
664
    return (flags_ & CONVERTER_FLAGS_IGNORE_BOM) == CONVERTER_FLAGS_IGNORE_BOM;
130
  }
131
132
 private:
133
  int flags_ = 0;
134
};
135
136
}  // namespace i18n
137
}  // namespace node
138
139
#endif  // NODE_HAVE_I18N_SUPPORT
140
141
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
142
143
#endif  // SRC_NODE_I18N_H_