@@ -46,11 +46,13 @@ using v8::Value;
46
46
47
47
namespace url {
48
48
49
+ namespace {
50
+
49
51
// https://url.spec.whatwg.org/#eof-code-point
50
- static const char kEOL = -1 ;
52
+ const char kEOL = -1 ;
51
53
52
54
// Used in ToUSVString().
53
- static const char16_t kUnicodeReplacementCharacter = 0xFFFD ;
55
+ const char16_t kUnicodeReplacementCharacter = 0xFFFD ;
54
56
55
57
// https://url.spec.whatwg.org/#concept-host
56
58
union url_host_value {
@@ -103,21 +105,21 @@ enum url_error_cb_args {
103
105
104
106
#define CHAR_TEST (bits, name, expr ) \
105
107
template <typename T> \
106
- static inline bool name (const T ch) { \
108
+ inline bool name (const T ch) { \
107
109
static_assert (sizeof (ch) >= (bits) / 8 , \
108
110
" Character must be wider than " #bits " bits" ); \
109
111
return (expr); \
110
112
}
111
113
112
114
#define TWO_CHAR_STRING_TEST (bits, name, expr ) \
113
115
template <typename T> \
114
- static inline bool name (const T ch1, const T ch2) { \
116
+ inline bool name (const T ch1, const T ch2) { \
115
117
static_assert (sizeof (ch1) >= (bits) / 8 , \
116
118
" Character must be wider than " #bits " bits" ); \
117
119
return (expr); \
118
120
} \
119
121
template <typename T> \
120
- static inline bool name (const std::basic_string<T>& str) { \
122
+ inline bool name (const std::basic_string<T>& str) { \
121
123
static_assert (sizeof (str[0 ]) >= (bits) / 8 , \
122
124
" Character must be wider than " #bits " bits" ); \
123
125
return str.length () >= 2 && name (str[0 ], str[1 ]); \
@@ -146,7 +148,7 @@ CHAR_TEST(8, IsASCIIAlphanumeric, (IsASCIIDigit(ch) || IsASCIIAlpha(ch)))
146
148
147
149
// https://infra.spec.whatwg.org/#ascii-lowercase
148
150
template <typename T>
149
- static inline T ASCIILowercase (T ch) {
151
+ inline T ASCIILowercase (T ch) {
150
152
return IsASCIIAlpha (ch) ? (ch | 0x20 ) : ch;
151
153
}
152
154
@@ -177,7 +179,7 @@ CHAR_TEST(16, IsUnicodeSurrogateTrail, (ch & 0x400) != 0)
177
179
#undef CHAR_TEST
178
180
#undef TWO_CHAR_STRING_TEST
179
181
180
- static const char * hex[256 ] = {
182
+ const char * hex[256 ] = {
181
183
" %00" , " %01" , " %02" , " %03" , " %04" , " %05" , " %06" , " %07" ,
182
184
" %08" , " %09" , " %0A" , " %0B" , " %0C" , " %0D" , " %0E" , " %0F" ,
183
185
" %10" , " %11" , " %12" , " %13" , " %14" , " %15" , " %16" , " %17" ,
@@ -212,7 +214,7 @@ static const char* hex[256] = {
212
214
" %F8" , " %F9" , " %FA" , " %FB" , " %FC" , " %FD" , " %FE" , " %FF"
213
215
};
214
216
215
- static const uint8_t C0_CONTROL_ENCODE_SET[32 ] = {
217
+ const uint8_t C0_CONTROL_ENCODE_SET[32 ] = {
216
218
// 00 01 02 03 04 05 06 07
217
219
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80 ,
218
220
// 08 09 0A 0B 0C 0D 0E 0F
@@ -279,7 +281,7 @@ static const uint8_t C0_CONTROL_ENCODE_SET[32] = {
279
281
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
280
282
};
281
283
282
- static const uint8_t PATH_ENCODE_SET[32 ] = {
284
+ const uint8_t PATH_ENCODE_SET[32 ] = {
283
285
// 00 01 02 03 04 05 06 07
284
286
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80 ,
285
287
// 08 09 0A 0B 0C 0D 0E 0F
@@ -346,7 +348,7 @@ static const uint8_t PATH_ENCODE_SET[32] = {
346
348
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
347
349
};
348
350
349
- static const uint8_t USERINFO_ENCODE_SET[32 ] = {
351
+ const uint8_t USERINFO_ENCODE_SET[32 ] = {
350
352
// 00 01 02 03 04 05 06 07
351
353
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80 ,
352
354
// 08 09 0A 0B 0C 0D 0E 0F
@@ -413,7 +415,7 @@ static const uint8_t USERINFO_ENCODE_SET[32] = {
413
415
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
414
416
};
415
417
416
- static const uint8_t QUERY_ENCODE_SET[32 ] = {
418
+ const uint8_t QUERY_ENCODE_SET[32 ] = {
417
419
// 00 01 02 03 04 05 06 07
418
420
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80 ,
419
421
// 08 09 0A 0B 0C 0D 0E 0F
@@ -480,23 +482,23 @@ static const uint8_t QUERY_ENCODE_SET[32] = {
480
482
0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80
481
483
};
482
484
483
- static inline bool BitAt (const uint8_t a[], const uint8_t i) {
485
+ inline bool BitAt (const uint8_t a[], const uint8_t i) {
484
486
return !!(a[i >> 3 ] & (1 << (i & 7 )));
485
487
}
486
488
487
489
// Appends ch to str. If ch position in encode_set is set, the ch will
488
490
// be percent-encoded then appended.
489
- static inline void AppendOrEscape (std::string* str,
490
- const unsigned char ch,
491
- const uint8_t encode_set[]) {
491
+ inline void AppendOrEscape (std::string* str,
492
+ const unsigned char ch,
493
+ const uint8_t encode_set[]) {
492
494
if (BitAt (encode_set, ch))
493
495
*str += hex[ch];
494
496
else
495
497
*str += ch;
496
498
}
497
499
498
500
template <typename T>
499
- static inline unsigned hex2bin (const T ch) {
501
+ inline unsigned hex2bin (const T ch) {
500
502
if (ch >= ' 0' && ch <= ' 9' )
501
503
return ch - ' 0' ;
502
504
if (ch >= ' A' && ch <= ' F' )
@@ -544,16 +546,15 @@ inline std::string PercentDecode(const char* input, size_t len) {
544
546
XX (" ws:" , 80 ) \
545
547
XX (" wss:" , 443 )
546
548
547
- static inline bool IsSpecial (std::string scheme) {
549
+ inline bool IsSpecial (std::string scheme) {
548
550
#define XX (name, _ ) if (scheme == name) return true ;
549
551
SPECIALS (XX);
550
552
#undef XX
551
553
return false ;
552
554
}
553
555
554
556
// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
555
- static inline bool StartsWithWindowsDriveLetter (const char * p,
556
- const char * end) {
557
+ inline bool StartsWithWindowsDriveLetter (const char * p, const char * end) {
557
558
const size_t length = end - p;
558
559
return length >= 2 &&
559
560
IsWindowsDriveLetter (p[0 ], p[1 ]) &&
@@ -564,23 +565,23 @@ static inline bool StartsWithWindowsDriveLetter(const char* p,
564
565
p[2 ] == ' #' );
565
566
}
566
567
567
- static inline int NormalizePort (std::string scheme, int p) {
568
+ inline int NormalizePort (std::string scheme, int p) {
568
569
#define XX (name, port ) if (scheme == name && p == port) return -1 ;
569
570
SPECIALS (XX);
570
571
#undef XX
571
572
return p;
572
573
}
573
574
574
575
#if defined(NODE_HAVE_I18N_SUPPORT)
575
- static inline bool ToUnicode (const std::string& input, std::string* output) {
576
+ inline bool ToUnicode (const std::string& input, std::string* output) {
576
577
MaybeStackBuffer<char > buf;
577
578
if (i18n::ToUnicode (&buf, input.c_str (), input.length ()) < 0 )
578
579
return false ;
579
580
output->assign (*buf, buf.length ());
580
581
return true ;
581
582
}
582
583
583
- static inline bool ToASCII (const std::string& input, std::string* output) {
584
+ inline bool ToASCII (const std::string& input, std::string* output) {
584
585
MaybeStackBuffer<char > buf;
585
586
if (i18n::ToASCII (&buf, input.c_str (), input.length ()) < 0 )
586
587
return false ;
@@ -589,20 +590,18 @@ static inline bool ToASCII(const std::string& input, std::string* output) {
589
590
}
590
591
#else
591
592
// Intentional non-ops if ICU is not present.
592
- static inline bool ToUnicode (const std::string& input, std::string* output) {
593
+ inline bool ToUnicode (const std::string& input, std::string* output) {
593
594
*output = input;
594
595
return true ;
595
596
}
596
597
597
- static inline bool ToASCII (const std::string& input, std::string* output) {
598
+ inline bool ToASCII (const std::string& input, std::string* output) {
598
599
*output = input;
599
600
return true ;
600
601
}
601
602
#endif
602
603
603
- static url_host_type ParseIPv6Host (url_host* host,
604
- const char * input,
605
- size_t length) {
604
+ url_host_type ParseIPv6Host (url_host* host, const char * input, size_t length) {
606
605
url_host_type type = HOST_TYPE_FAILED;
607
606
for (unsigned n = 0 ; n < 8 ; n++)
608
607
host->value .ipv6 [n] = 0 ;
@@ -720,7 +719,7 @@ static url_host_type ParseIPv6Host(url_host* host,
720
719
return type;
721
720
}
722
721
723
- static inline int64_t ParseNumber (const char * start, const char * end) {
722
+ inline int64_t ParseNumber (const char * start, const char * end) {
724
723
unsigned R = 10 ;
725
724
if (end - start >= 2 && start[0 ] == ' 0' && (start[1 ] | 0x20 ) == ' x' ) {
726
725
start += 2 ;
@@ -755,9 +754,7 @@ static inline int64_t ParseNumber(const char* start, const char* end) {
755
754
return strtoll (start, NULL , R);
756
755
}
757
756
758
- static url_host_type ParseIPv4Host (url_host* host,
759
- const char * input,
760
- size_t length) {
757
+ url_host_type ParseIPv4Host (url_host* host, const char * input, size_t length) {
761
758
url_host_type type = HOST_TYPE_DOMAIN;
762
759
const char * pointer = input;
763
760
const char * mark = input;
@@ -816,9 +813,9 @@ static url_host_type ParseIPv4Host(url_host* host,
816
813
return type;
817
814
}
818
815
819
- static url_host_type ParseOpaqueHost (url_host* host,
820
- const char * input,
821
- size_t length) {
816
+ url_host_type ParseOpaqueHost (url_host* host,
817
+ const char * input,
818
+ size_t length) {
822
819
url_host_type type = HOST_TYPE_OPAQUE;
823
820
std::string output;
824
821
output.reserve (length * 3 );
@@ -838,11 +835,11 @@ static url_host_type ParseOpaqueHost(url_host* host,
838
835
return type;
839
836
}
840
837
841
- static url_host_type ParseHost (url_host* host,
842
- const char * input,
843
- size_t length,
844
- bool is_special,
845
- bool unicode = false ) {
838
+ url_host_type ParseHost (url_host* host,
839
+ const char * input,
840
+ size_t length,
841
+ bool is_special,
842
+ bool unicode = false ) {
846
843
url_host_type type = HOST_TYPE_FAILED;
847
844
const char * pointer = input;
848
845
std::string decoded;
@@ -895,7 +892,7 @@ static url_host_type ParseHost(url_host* host,
895
892
// Locates the longest sequence of 0 segments in an IPv6 address
896
893
// in order to use the :: compression when serializing
897
894
template <typename T>
898
- static inline T* FindLongestZeroSequence (T* values, size_t len) {
895
+ inline T* FindLongestZeroSequence (T* values, size_t len) {
899
896
T* start = values;
900
897
T* end = start + len;
901
898
T* result = nullptr ;
@@ -923,7 +920,7 @@ static inline T* FindLongestZeroSequence(T* values, size_t len) {
923
920
return result;
924
921
}
925
922
926
- static url_host_type WriteHost (const url_host* host, std::string* dest) {
923
+ url_host_type WriteHost (const url_host* host, std::string* dest) {
927
924
dest->clear ();
928
925
switch (host->type ) {
929
926
case HOST_TYPE_DOMAIN:
@@ -978,10 +975,10 @@ static url_host_type WriteHost(const url_host* host, std::string* dest) {
978
975
return host->type ;
979
976
}
980
977
981
- static bool ParseHost (const std::string& input,
982
- std::string* output,
983
- bool is_special,
984
- bool unicode = false ) {
978
+ bool ParseHost (const std::string& input,
979
+ std::string* output,
980
+ bool is_special,
981
+ bool unicode = false ) {
985
982
if (input.length () == 0 ) {
986
983
output->clear ();
987
984
return true ;
@@ -994,9 +991,9 @@ static bool ParseHost(const std::string& input,
994
991
return true ;
995
992
}
996
993
997
- static inline void Copy (Environment* env,
998
- Local<Array> ary,
999
- std::vector<std::string>* vec) {
994
+ inline void Copy (Environment* env,
995
+ Local<Array> ary,
996
+ std::vector<std::string>* vec) {
1000
997
const int32_t len = ary->Length ();
1001
998
if (len == 0 )
1002
999
return ; // nothing to copy
@@ -1010,18 +1007,18 @@ static inline void Copy(Environment* env,
1010
1007
}
1011
1008
}
1012
1009
1013
- static inline Local<Array> Copy (Environment* env,
1014
- const std::vector<std::string>& vec) {
1010
+ inline Local<Array> Copy (Environment* env,
1011
+ const std::vector<std::string>& vec) {
1015
1012
Isolate* isolate = env->isolate ();
1016
1013
Local<Array> ary = Array::New (isolate, vec.size ());
1017
1014
for (size_t n = 0 ; n < vec.size (); n++)
1018
1015
ary->Set (env->context (), n, UTF8STRING (isolate, vec[n])).FromJust ();
1019
1016
return ary;
1020
1017
}
1021
1018
1022
- static inline void HarvestBase (Environment* env,
1023
- struct url_data * base,
1024
- Local<Object> base_obj) {
1019
+ inline void HarvestBase (Environment* env,
1020
+ struct url_data * base,
1021
+ Local<Object> base_obj) {
1025
1022
Local<Context> context = env->context ();
1026
1023
Local<Value> flags = GET (env, base_obj, " flags" );
1027
1024
if (flags->IsInt32 ())
@@ -1045,9 +1042,9 @@ static inline void HarvestBase(Environment* env,
1045
1042
}
1046
1043
}
1047
1044
1048
- static inline void HarvestContext (Environment* env,
1049
- struct url_data * context,
1050
- Local<Object> context_obj) {
1045
+ inline void HarvestContext (Environment* env,
1046
+ struct url_data * context,
1047
+ Local<Object> context_obj) {
1051
1048
Local<Value> flags = GET (env, context_obj, " flags" );
1052
1049
if (flags->IsInt32 ()) {
1053
1050
int32_t _flags = flags->Int32Value (env->context ()).FromJust ();
@@ -1090,7 +1087,7 @@ static inline void HarvestContext(Environment* env,
1090
1087
}
1091
1088
1092
1089
// Single dot segment can be ".", "%2e", or "%2E"
1093
- static inline bool IsSingleDotSegment (const std::string& str) {
1090
+ inline bool IsSingleDotSegment (const std::string& str) {
1094
1091
switch (str.size ()) {
1095
1092
case 1 :
1096
1093
return str == " ." ;
@@ -1106,7 +1103,7 @@ static inline bool IsSingleDotSegment(const std::string& str) {
1106
1103
// Double dot segment can be:
1107
1104
// "..", ".%2e", ".%2E", "%2e.", "%2E.",
1108
1105
// "%2e%2e", "%2E%2E", "%2e%2E", or "%2E%2e"
1109
- static inline bool IsDoubleDotSegment (const std::string& str) {
1106
+ inline bool IsDoubleDotSegment (const std::string& str) {
1110
1107
switch (str.size ()) {
1111
1108
case 2 :
1112
1109
return str == " .." ;
@@ -1133,13 +1130,15 @@ static inline bool IsDoubleDotSegment(const std::string& str) {
1133
1130
}
1134
1131
}
1135
1132
1136
- static inline void ShortenUrlPath (struct url_data * url) {
1133
+ inline void ShortenUrlPath (struct url_data * url) {
1137
1134
if (url->path .empty ()) return ;
1138
1135
if (url->path .size () == 1 && url->scheme == " file:" &&
1139
1136
IsNormalizedWindowsDriveLetter (url->path [0 ])) return ;
1140
1137
url->path .pop_back ();
1141
1138
}
1142
1139
1140
+ } // anonymous namespace
1141
+
1143
1142
void URL::Parse (const char * input,
1144
1143
size_t len,
1145
1144
enum url_parse_state state_override,
0 commit comments