pull/5770/merge
dataisland 2024-09-15 17:45:08 -05:00 committed by GitHub
commit d4ee164cf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -155,7 +155,7 @@ AI_FORCE_INLINE LineSplitter::LineSplitter(StreamReaderLE& stream, bool skip_emp
mSkip_empty_lines(skip_empty_lines), mSkip_empty_lines(skip_empty_lines),
mTrim(trim) { mTrim(trim) {
mCur.reserve(1024); mCur.reserve(1024);
mEnd = mCur.c_str() + 1024; mEnd = mCur.c_str() + mCur.capacity();
operator++(); operator++();
mIdx = 0; mIdx = 0;
} }
@ -172,6 +172,7 @@ AI_FORCE_INLINE LineSplitter& LineSplitter::operator++() {
char s; char s;
mCur.clear(); mCur.clear();
mEnd = mCur.c_str() + mCur.capacity();
while (mStream.GetRemainingSize() && (s = mStream.GetI1(), 1)) { while (mStream.GetRemainingSize() && (s = mStream.GetI1(), 1)) {
if (s == '\n' || s == '\r') { if (s == '\n' || s == '\r') {
if (mSkip_empty_lines) { if (mSkip_empty_lines) {
@ -194,6 +195,7 @@ AI_FORCE_INLINE LineSplitter& LineSplitter::operator++() {
break; break;
} }
mCur += s; mCur += s;
mEnd = mCur.c_str() + mCur.capacity();
} }
++mIdx; ++mIdx;

View File

@ -103,11 +103,11 @@ AI_FORCE_INLINE bool IsSpaceOrNewLine(char_t in) {
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out, const char_t *end) { AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out, const char_t *end) {
while ((*in == (char_t)' ' || *in == (char_t)'\t') && in != end) { while (in < end && (*in == (char_t)' ' || *in == (char_t)'\t')) {
++in; ++in;
} }
*out = in; *out = in;
return !IsLineEnd<char_t>(*in); return in < end && !IsLineEnd<char_t>(*in);
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
@ -119,16 +119,16 @@ AI_FORCE_INLINE bool SkipSpaces(const char_t **inout, const char_t *end) {
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out, const char_t *end) { AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out, const char_t *end) {
while ((*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0') && in != end) { while (in < end && (*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0')) {
++in; ++in;
} }
// files are opened in binary mode. Ergo there are both NL and CR // files are opened in binary mode. Ergo there are both NL and CR
while ((*in == (char_t)'\r' || *in == (char_t)'\n') && in != end) { while (in < end && (*in == (char_t)'\r' || *in == (char_t)'\n')) {
++in; ++in;
} }
*out = in; *out = in;
return *in != (char_t)'\0'; return in < end && *in != (char_t)'\0';
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
@ -140,11 +140,11 @@ AI_FORCE_INLINE bool SkipLine(const char_t **inout, const char_t *end) {
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out, const char_t *end) { AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out, const char_t *end) {
while ((*in == (char_t)' ' || *in == (char_t)'\t' || *in == (char_t)'\r' || *in == (char_t)'\n') && in != end) { while (in < end && (*in == (char_t)' ' || *in == (char_t)'\t' || *in == (char_t)'\r' || *in == (char_t)'\n')) {
++in; ++in;
} }
*out = in; *out = in;
return *in != '\0'; return in < end && *in != '\0';
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------