forked from gbdev/rgbds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Allow longer strings, not '\0'-terminated
Still to port from ISSOtm's strings branch: - lexer.c - parser.y - symbol.c Fixes gbdev#650 Fixes gbdev#505
- Loading branch information
Showing
15 changed files
with
315 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* This file is part of RGBDS. | ||
* | ||
* Copyright (c) 2021, Eldred Habert and RGBDS contributors. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#ifndef RGBDS_STRING_H | ||
#define RGBDS_STRING_H | ||
|
||
#include <assert.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#include "helpers.h" | ||
|
||
struct String; | ||
|
||
#define PRI_STR ".*s" | ||
// WARNING: **DO NOT** pass any side-effecting parameters to the macros below! | ||
#define STR_FMT(str) (int)str_Len(str), str_Chars(str) | ||
|
||
#define MUTATE_STR(str, ...) do { \ | ||
struct String *___orig_str = str; \ | ||
str = __VA_ARGS__; \ | ||
assert(___orig_str == str); /* This shouldn't have been reallocated */ \ | ||
} while (0) | ||
|
||
static inline bool str_IsWhitespace(int c) | ||
{ | ||
return c == ' ' || c == '\t'; | ||
} | ||
|
||
size_t str_Len(struct String const *str) pure_; | ||
void str_Trunc(struct String *str, size_t len); | ||
char str_Index(struct String const *str, size_t i) pure_; | ||
bool str_Find(struct String const *str, char c) pure_; | ||
char const *str_Chars(struct String const *str) pure_; | ||
|
||
/** | ||
* @param capacity The capacity to use, or 0 if unknown | ||
*/ | ||
struct String *str_New(size_t capacity) mallocish_; | ||
void str_Ref(struct String *str); | ||
void str_Unref(struct String *str); | ||
|
||
struct String *str_Push(struct String *str, char c) warn_unused_result_; | ||
struct String *str_Append(struct String *lhs, struct String const *rhs) warn_unused_result_; | ||
struct String *str_AppendSlice(struct String *lhs, char const *rhs, size_t len) warn_unused_result_; | ||
void str_TrimEnd(struct String *str); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.