59 lines
2.2 KiB
C
59 lines
2.2 KiB
C
|
/*
|
||
|
* This code is part of the programming language Ivy.
|
||
|
* Ivy comes with ABSOLUTELY NO WARRANTY and is licensed under AGPL-3.0 or later.
|
||
|
* Copyright (C) 2024 VegOwOtenks
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
#ifndef STRINGVIEW_H_
|
||
|
#define STRINGVIEW_H_
|
||
|
|
||
|
#include <stdbool.h>
|
||
|
#include <stddef.h>
|
||
|
|
||
|
// Generally, StringViews are not owned
|
||
|
|
||
|
typedef struct StringView_s {
|
||
|
const char *source;
|
||
|
size_t length;
|
||
|
} StringView;
|
||
|
|
||
|
#define STRINGVIEW_NONE ((StringView) {.source = NULL, .length = 0})
|
||
|
|
||
|
StringView StringView_FromString(const char* source);
|
||
|
StringView StringView_FromStringSized(const char* source, size_t length);
|
||
|
|
||
|
bool StringView_Equal(StringView first, StringView second);
|
||
|
bool StringView_StartsWith(StringView string, StringView start);
|
||
|
bool StringView_EndsWith(StringView string, StringView end);
|
||
|
bool StringView_Contains(StringView string, StringView find);
|
||
|
|
||
|
size_t StringView_Count(StringView string, StringView find);
|
||
|
|
||
|
size_t StringView_FindStringOffset(StringView haystack, StringView needle);
|
||
|
StringView StringView_FindString(StringView haystack, StringView needle);
|
||
|
StringView StringView_Slice(StringView string, size_t start, size_t end); // start and end are offsets
|
||
|
|
||
|
bool StringView_NextSplit(StringView* dest, StringView* source, StringView delim);
|
||
|
|
||
|
StringView StringView_StripLeft(StringView sv, StringView strip);
|
||
|
StringView StringView_StripRight(StringView sv, StringView strip);
|
||
|
|
||
|
void StringView_Paste(char* destination, StringView source);
|
||
|
|
||
|
int StringView_ParseInt(StringView source);
|
||
|
|
||
|
#endif /* SRC_STRINGVIEW_STRINGVIEW_H_ */
|