@@ -96,50 +96,50 @@ using v8::Value;
96
96
namespace url {
97
97
98
98
#if defined(NODE_HAVE_I18N_SUPPORT)
99
- static int ToUnicode (std::string* input, std::string* output) {
99
+ static bool ToUnicode (std::string* input, std::string* output) {
100
100
MaybeStackBuffer<char > buf;
101
101
if (i18n::ToUnicode (&buf, input->c_str (), input->length ()) < 0 )
102
- return - 1 ;
102
+ return false ;
103
103
output->assign (*buf, buf.length ());
104
- return 0 ;
104
+ return true ;
105
105
}
106
106
107
- static int ToASCII (std::string* input, std::string* output) {
107
+ static bool ToASCII (std::string* input, std::string* output) {
108
108
MaybeStackBuffer<char > buf;
109
109
if (i18n::ToASCII (&buf, input->c_str (), input->length ()) < 0 )
110
- return - 1 ;
110
+ return false ;
111
111
output->assign (*buf, buf.length ());
112
- return 0 ;
112
+ return true ;
113
113
}
114
114
115
115
// Unfortunately there's not really a better way to do this.
116
116
// Iterate through each encoded codepoint and verify that
117
117
// it is a valid unicode codepoint.
118
- static int IsValidUTF8 (std::string* input) {
118
+ static bool IsValidUTF8 (std::string* input) {
119
119
const char * p = input->c_str ();
120
120
int32_t len = input->length ();
121
121
for (int32_t i = 0 ; i < len;) {
122
122
UChar32 c;
123
123
U8_NEXT_UNSAFE (p, i, c);
124
124
if (!U_IS_UNICODE_CHAR (c))
125
- return - 1 ;
125
+ return false ;
126
126
}
127
- return 0 ;
127
+ return true ;
128
128
}
129
129
#else
130
130
// Intentional non-ops if ICU is not present.
131
- static int ToUnicode (std::string* input, std::string* output) {
132
- output-> reserve ( input-> length ()) ;
133
- *output = input-> c_str () ;
131
+ static bool ToUnicode (std::string* input, std::string* output) {
132
+ * output = * input;
133
+ return true ;
134
134
}
135
135
136
- static int ToASCII (std::string* input, std::string* output) {
137
- output-> reserve ( input-> length ()) ;
138
- *output = input-> c_str () ;
136
+ static bool ToASCII (std::string* input, std::string* output) {
137
+ * output = * input;
138
+ return true ;
139
139
}
140
140
141
- static int IsValidUTF8 (std::string* input) {
142
- return 0 ;
141
+ static bool IsValidUTF8 (std::string* input) {
142
+ return true ;
143
143
}
144
144
#endif
145
145
@@ -381,11 +381,11 @@ namespace url {
381
381
// If there are any invalid UTF8 byte sequences, we have to fail.
382
382
// Unfortunately this means iterating through the string and checking
383
383
// each decoded codepoint.
384
- if (IsValidUTF8 (&decoded) < 0 )
384
+ if (! IsValidUTF8 (&decoded))
385
385
goto end;
386
386
387
387
// Then we have to punycode toASCII
388
- if (ToASCII (&decoded, &decoded) < 0 )
388
+ if (! ToASCII (&decoded, &decoded))
389
389
goto end;
390
390
391
391
// If any of the following characters are still present, we have to fail
@@ -405,7 +405,7 @@ namespace url {
405
405
goto end;
406
406
407
407
// If the unicode flag is set, run the result through punycode ToUnicode
408
- if (unicode && ToUnicode (&decoded, &decoded) < 0 )
408
+ if (unicode && ! ToUnicode (&decoded, &decoded))
409
409
goto end;
410
410
411
411
// It's not an IPv4 or IPv6 address, it must be a domain
@@ -499,17 +499,17 @@ namespace url {
499
499
return host->type ;
500
500
}
501
501
502
- static int ParseHost (std::string* input,
503
- std::string* output,
504
- bool unicode = false ) {
502
+ static bool ParseHost (std::string* input,
503
+ std::string* output,
504
+ bool unicode = false ) {
505
505
if (input->length () == 0 )
506
- return 0 ;
506
+ return true ;
507
507
url_host host{{" " }, HOST_TYPE_DOMAIN};
508
508
ParseHost (&host, input->c_str (), input->length (), unicode);
509
509
if (host.type == HOST_TYPE_FAILED)
510
- return - 1 ;
510
+ return false ;
511
511
WriteHost (&host, output);
512
- return 0 ;
512
+ return true ;
513
513
}
514
514
515
515
static inline void Copy (Isolate* isolate,
@@ -996,7 +996,7 @@ namespace url {
996
996
if (special && buffer.size () == 0 )
997
997
URL_FAILED ()
998
998
SET_HAVE_HOST ()
999
- if (ParseHost (&buffer, &url.host ) < 0 )
999
+ if (! ParseHost (&buffer, &url.host ))
1000
1000
URL_FAILED ()
1001
1001
buffer.clear ();
1002
1002
state = kPort ;
@@ -1011,7 +1011,7 @@ namespace url {
1011
1011
if (special && buffer.size () == 0 )
1012
1012
URL_FAILED ()
1013
1013
SET_HAVE_HOST ()
1014
- if (ParseHost (&buffer, &url.host ) < 0 )
1014
+ if (! ParseHost (&buffer, &url.host ))
1015
1015
URL_FAILED ()
1016
1016
buffer.clear ();
1017
1017
state = kPathStart ;
@@ -1161,7 +1161,7 @@ namespace url {
1161
1161
} else {
1162
1162
if (buffer != " localhost" ) {
1163
1163
SET_HAVE_HOST ()
1164
- if (ParseHost (&buffer, &url.host ) < 0 )
1164
+ if (! ParseHost (&buffer, &url.host ))
1165
1165
URL_FAILED ()
1166
1166
}
1167
1167
buffer.clear ();
0 commit comments