MCPcopy Create free account
hub / github.com/d3x0r/JSON6 / gatherString

Function gatherString

lib/json6.js:397–542  ·  view source on GitHub ↗
( start_c )

Source from the content-addressed store, hash-verified

395 }
396
397 function gatherString( start_c ) {
398 let retval = 0;
399 while( retval == 0 && ( n < buf.length ) ) {
400 let str = buf.charAt(n);
401 const cInt = buf.codePointAt(n++);
402 if( cInt >= 0x10000 ) { str += buf.charAt(n); n++; }
403 //console.log( "gathering....", stringEscape, str, cInt, unicodeWide, stringHex, stringUnicode, hex_char_len );
404 pos.col++;
405 if( cInt == start_c ) {//( cInt == 34/*'"'*/ ) || ( cInt == 39/*'\''*/ ) || ( cInt == 96/*'`'*/ ) )
406 if( stringEscape ) {
407 if( stringHex )
408 throwError( "Incomplete hexidecimal sequence", cInt );
409 else if( unicodeWide )
410 throwError( "Incomplete long unicode sequence", cInt );
411 else if( stringUnicode )
412 throwError( "Incomplete unicode sequence", cInt );
413
414 if( cr_escaped ) {
415 cr_escaped = false; // \\ \r ' :end string, the backslash was used for \r
416 retval = 1; // complete string.
417 } else val.string += str; // escaped start quote
418 stringEscape = false;
419 }
420 else {
421 // quote matches, not escaped, and not processing escape...
422 retval = 1;
423 }
424 }
425
426 else if( stringEscape ) {
427 if( unicodeWide ) {
428 if( cInt == 125/*'}'*/ ) {
429 val.string += String.fromCodePoint( hex_char );
430 unicodeWide = false;
431 stringUnicode = false;
432 stringEscape = false;
433 continue;
434 }
435 hex_char *= 16;
436 if( cInt >= 48/*'0'*/ && cInt <= 57/*'9'*/ ) hex_char += cInt - 0x30;
437 else if( cInt >= 65/*'A'*/ && cInt <= 70/*'F'*/ ) hex_char += ( cInt - 65 ) + 10;
438 else if( cInt >= 97/*'a'*/ && cInt <= 102/*'f'*/ ) hex_char += ( cInt - 97 ) + 10;
439 else {
440 throwError( "(escaped character, parsing hex of \\u)", cInt );
441 }
442 continue;
443 }
444 else if( stringHex || stringUnicode ) {
445 if( hex_char_len === 0 && cInt === 123/*'{'*/ ) {
446 unicodeWide = true;
447 continue;
448 }
449 hex_char *= 16;
450 if( cInt >= 48/*'0'*/ && cInt <= 57/*'9'*/ ) hex_char += cInt - 0x30;
451 else if( cInt >= 65/*'A'*/ && cInt <= 70/*'F'*/ ) hex_char += ( cInt - 65 ) + 10;
452 else if( cInt >= 97/*'a'*/ && cInt <= 102/*'f'*/ ) hex_char += ( cInt - 97 ) + 10;
453 else {
454 throwError( stringUnicode?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)", cInt );

Callers 1

_writeFunction · 0.85

Calls 1

throwErrorFunction · 0.85

Tested by

no test coverage detected