MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Stream_ReadLine

Function Stream_ReadLine

src/Stream.c:465–497  ·  view source on GitHub ↗

#######################################################################################################################* *--------------------------------------------------Read/Write strings-----------------------------------------------------* *#########################################################################################################################*/

Source from the content-addressed store, hash-verified

463*--------------------------------------------------Read/Write strings-----------------------------------------------------*
464*#########################################################################################################################*/
465cc_result Stream_ReadLine(struct Stream* s, cc_string* text) {
466 cc_bool readAny = false;
467 cc_codepoint cp;
468 cc_result res;
469
470 cc_uint8 tmp[8];
471 cc_uint32 len;
472
473 text->length = 0;
474 for (;;) {
475 len = 0;
476
477 /* Read a UTF8 character from the stream */
478 /* (in most cases it's just one byte) */
479 do {
480 if ((res = s->ReadU8(s, &tmp[len]))) break;
481 len++;
482 } while (!Convert_Utf8ToCodepoint(&cp, tmp, len));
483
484 if (res == ERR_END_OF_STREAM) break;
485 if (res) return res;
486
487 readAny = true;
488 /* Handle \r\n or \n line endings */
489 if (cp == '\r') continue;
490 if (cp == '\n') return 0;
491
492 /* ignore byte order mark */
493 if (cp == 0xFEFF) continue;
494 String_Append(text, Convert_CodepointToCP437(cp));
495 }
496 return readAny ? 0 : ERR_END_OF_STREAM;
497}
498
499cc_result Stream_WriteLine(struct Stream* s, cc_string* text) {
500 cc_uint8 buffer[2048 + 10]; /* some space for newline */

Callers 3

EntryList_LoadFunction · 0.85
WoM_ParseConfigFunction · 0.85

Calls 3

Convert_Utf8ToCodepointFunction · 0.85
String_AppendFunction · 0.85
Convert_CodepointToCP437Function · 0.85

Tested by

no test coverage detected