MCPcopy Create free account
hub / github.com/SpartanJ/eepp / ptrGetLine

Function ptrGetLine

src/eepp/ui/doc/textdocument.cpp:447–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447static String ptrGetLine( char* data, const size_t& size, size_t& position,
448 TextFormat::Encoding enc ) {
449 static constexpr auto LE_END_LF = "\n\0"sv;
450 static constexpr auto LE_END_CR = "\r\0"sv;
451 static constexpr auto BE_END_LF = "\0\n"sv;
452 static constexpr auto BE_END_CR = "\0\r"sv;
453 position = 0;
454 switch ( enc ) {
455 case TextFormat::Encoding::UTF16LE: {
456 searchSubstr( data, size, position, LE_END_LF, LE_END_CR, codepointSize( enc ) );
457 if ( position == size )
458 return "";
459 return String::fromUtf16( data, position, false );
460 }
461 case TextFormat::Encoding::UTF16BE: {
462 searchSubstr( data, size, position, BE_END_LF, BE_END_CR, codepointSize( enc ) );
463 if ( position == size )
464 return "";
465 return String::fromUtf16( data, position, true );
466 }
467 case TextFormat::Encoding::UTF8:
468 case TextFormat::Encoding::Latin1:
469 default:
470 break;
471 }
472
473 while ( position < size && data[position] != '\n' && data[position] != '\r' )
474 position++;
475 if ( position < size ) {
476 if ( position + 1 < size && data[position] == '\r' && data[position + 1] == '\n' )
477 position++;
478 position++;
479 }
480
481 if ( enc == TextFormat::Encoding::Shift_JIS )
482 return shiftJISToUTF32( std::string_view{ data, position } );
483 else if ( enc == TextFormat::Encoding::Latin1 )
484 return String::fromLatin1( data, position );
485
486 return String( data, position );
487}
488
489TextDocument::LoadStatus TextDocument::loadFromStream( IOStream& file ) {
490 return loadFromStream( file, "untitled", true );

Callers 1

loadFromStreamMethod · 0.85

Calls 3

searchSubstrFunction · 0.85
codepointSizeFunction · 0.85
shiftJISToUTF32Function · 0.85

Tested by

no test coverage detected