| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,11 +200,21 @@ export function request(options: httpModule.HttpRequestOptions): Promise<httpMod | |||
| 200 | 200 | } | |
| 201 | 201 | ||
| 202 | 202 | function NSDataToString(data: any, encoding?: HttpResponseEncoding): string { | |
| 203 | - let code = 4; //UTF8 | ||
| 203 | + let code = NSUTF8StringEncoding; // long:4 | ||
| 204 | + | ||
| 204 | 205 | if (encoding === HttpResponseEncoding.GBK) { | |
| 205 | - code = 1586; | ||
| 206 | + code = CFStringEncodings.kCFStringEncodingGB_18030_2000; // long:1586 | ||
| 206 | 207 | } | |
| 207 | - return NSString.alloc().initWithDataEncoding(data, code).toString(); | ||
| 208 | + | ||
| 209 | + let encodedString = NSString.alloc().initWithDataEncoding(data, code); | ||
| 210 | + | ||
| 211 | + // If UTF8 string encoding fails try with ISO-8859-1 | ||
| 212 | + if (!encodedString) { | ||
| 213 | + code = NSISOLatin1StringEncoding; // long:5 | ||
| 214 | + encodedString = NSString.alloc().initWithDataEncoding(data, code); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + return encodedString.toString(); | ||
| 208 | 218 | } | |
| 209 | 219 | ||
| 210 | 220 | export function addHeader(headers: httpModule.Headers, key: string, value: string): void { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments