|
|
@@ -2,6 +2,7 @@
|
|
|
#include "pocketpy/common/sstream.h"
|
|
|
#include "pocketpy/common/utils.h"
|
|
|
|
|
|
+#include <ctype.h>
|
|
|
#include <string.h>
|
|
|
#include <stdio.h>
|
|
|
#include <assert.h>
|
|
|
@@ -188,6 +189,26 @@ uint64_t c11_sv__hash(c11_sv self) {
|
|
|
return hash;
|
|
|
}
|
|
|
|
|
|
+c11_vector /* T=c11_sv */ c11_sv__splitwhitespace(c11_sv self) {
|
|
|
+ c11_vector retval;
|
|
|
+ c11_vector__ctor(&retval, sizeof(c11_sv));
|
|
|
+ const char* data = self.data;
|
|
|
+ int i = 0;
|
|
|
+ for(int j = 0; j < self.size; j++) {
|
|
|
+ if(isspace(data[j])) {
|
|
|
+ assert(j >= i);
|
|
|
+ c11_sv tmp = {data + i, j - i};
|
|
|
+ c11_vector__push(c11_sv, &retval, tmp);
|
|
|
+ i = j + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i <= self.size) {
|
|
|
+ c11_sv tmp = {data + i, self.size - i};
|
|
|
+ c11_vector__push(c11_sv, &retval, tmp);
|
|
|
+ }
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
c11_vector /* T=c11_sv */ c11_sv__split(c11_sv self, char sep) {
|
|
|
c11_vector retval;
|
|
|
c11_vector__ctor(&retval, sizeof(c11_sv));
|