remove trailing newline

This commit is contained in:
blueloveTH 2025-08-05 13:40:01 +08:00
parent ad107860e3
commit b7abcf19b1
3 changed files with 14 additions and 2 deletions

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
// clang-format off // clang-format off
#define PK_VERSION "2.1.0" #define PK_VERSION "2.1.1"
#define PK_VERSION_MAJOR 2 #define PK_VERSION_MAJOR 2
#define PK_VERSION_MINOR 1 #define PK_VERSION_MINOR 1
#define PK_VERSION_PATCH 0 #define PK_VERSION_PATCH 1
/*************** feature settings ***************/ /*************** feature settings ***************/
#ifndef PK_ENABLE_OS // can be overridden by cmake #ifndef PK_ENABLE_OS // can be overridden by cmake

View File

@ -24,6 +24,16 @@ static void SourceData__ctor(struct SourceData* self,
source++; source++;
} }
self->source = c11_sbuf__submit(&ss); self->source = c11_sbuf__submit(&ss);
// remove trailing newline
int last_index = self->source->size - 1;
while(last_index >= 0 && isspace(self->source->data[last_index])) {
last_index--;
}
if(last_index >= 0) {
self->source->size = last_index + 1;
self->source->data[last_index + 1] = '\0';
}
self->is_dynamic = is_dynamic; self->is_dynamic = is_dynamic;
c11_vector__push(const char*, &self->line_starts, self->source->data); c11_vector__push(const char*, &self->line_starts, self->source->data);
} }

View File

@ -74,3 +74,5 @@ exec(code, {'x': 42, 'res': res})
assert res == [42, 42] assert res == [42, 42]
assert x == 33 assert x == 33
# test removing trailing newlines
assert eval('[1, 2, 3]\n \n') == [1, 2, 3]