Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/node_i18n.h
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, std::string* error); 42 43 void SetDefaultTimeZone(const char* tzid); 44 45 enum class idna_mode { 46 // Default mode for maximum compatibility. 47 kDefault, 48 // Ignore all errors in IDNA conversion, if possible. 49 kLenient, 50 // Enforce STD3 rules (UseSTD3ASCIIRules) and DNS length restrictions 51 // (VerifyDnsLength). Corresponds to `beStrict` flag in the "domain to ASCII" 52 // algorithm. 53 kStrict 54 }; 55 56 struct ConverterDeleter { 57 void operator()(UConverter* pointer) const { ucnv_close(pointer); } 58 }; 59 using ConverterPointer = std::unique_ptr<UConverter, ConverterDeleter>; 60 61 class Converter { 62 public: 63 explicit Converter(const char* name, const char* sub = nullptr); 64 explicit Converter(UConverter* converter, const char* sub = nullptr); 65 66 UConverter* conv() const { return conv_.get(); } 67 68 size_t max_char_size() const; 69 size_t min_char_size() const; 70 void reset(); 71 void set_subst_chars(const char* sub = nullptr); 72 73 private: 74 ConverterPointer conv_; 75 }; 76 77 class ConverterObject : public BaseObject, Converter { 78 public: 79 enum ConverterFlags { 80 CONVERTER_FLAGS_FLUSH = 0x1, 81 CONVERTER_FLAGS_FATAL = 0x2, 82 CONVERTER_FLAGS_IGNORE_BOM = 0x4, 83 CONVERTER_FLAGS_UNICODE = 0x8, 84 CONVERTER_FLAGS_BOM_SEEN = 0x10, 85 }; 86 87 static void Create(const v8::FunctionCallbackInfo<v8::Value>& args); 88 static void Decode(const v8::FunctionCallbackInfo<v8::Value>& args); 89 static void Has(const v8::FunctionCallbackInfo<v8::Value>& args); 90 91 SET_NO_MEMORY_INFO() 92 SET_MEMORY_INFO_NAME(ConverterObject) 93 SET_SELF_SIZE(ConverterObject) 94 95 protected: 96 ConverterObject(Environment* env, 97 v8::Local<v8::Object> wrap, 98 UConverter* converter, 99 int flags, 100 const char* sub = nullptr); 101 102 void set_bom_seen(bool seen) { 103 if (seen) 104 flags_ |= CONVERTER_FLAGS_BOM_SEEN; 105 else 106 flags_ &= ~CONVERTER_FLAGS_BOM_SEEN; 107 } 108 109 bool bom_seen() const { 110 return (flags_ & CONVERTER_FLAGS_BOM_SEEN) == CONVERTER_FLAGS_BOM_SEEN; 111 } 112 113 bool unicode() const { 114 return (flags_ & CONVERTER_FLAGS_UNICODE) == CONVERTER_FLAGS_UNICODE; 115 } 116 117 bool ignore_bom() const { 118 return (flags_ & CONVERTER_FLAGS_IGNORE_BOM) == CONVERTER_FLAGS_IGNORE_BOM; 119 } 120 121 private: 122 int flags_ = 0; 123 }; 124 125 } // namespace i18n 126 } // namespace node 127 128 #endif // NODE_HAVE_I18N_SUPPORT 129 130 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 131 132 #endif // SRC_NODE_I18N_H_