2023-11-03 12:25:02 -04:00
|
|
|
/*
|
2024-10-15 11:47:13 -04:00
|
|
|
Copyright 2017-2024 Ian Jauslin
|
2023-11-03 12:25:02 -04:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DSTRING_H
|
|
|
|
#define DSTRING_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
typedef struct dstring {
|
|
|
|
char* string;
|
|
|
|
unsigned int length;
|
|
|
|
unsigned int memory;
|
|
|
|
} dstring;
|
|
|
|
|
|
|
|
// init
|
|
|
|
int dstring_init (dstring* str, unsigned int memory);
|
|
|
|
int dstring_free (dstring str);
|
|
|
|
|
|
|
|
// resize memory
|
|
|
|
int dstring_resize (dstring* str, unsigned int newsize);
|
|
|
|
|
|
|
|
// add a character
|
|
|
|
int dstring_append (char val, dstring* output);
|
|
|
|
|
|
|
|
// copy
|
|
|
|
int dstring_cpy (dstring input, dstring* output);
|
|
|
|
// do not init output str
|
|
|
|
int dstring_cpy_noinit (dstring input, dstring* output);
|
|
|
|
|
|
|
|
|
|
|
|
// concatenate
|
|
|
|
int dstring_concat (dstring input, dstring* output);
|
|
|
|
|
|
|
|
// sub-str
|
|
|
|
int dstring_substr (dstring str, unsigned int begin, unsigned int end, dstring* substr);
|
|
|
|
|
|
|
|
// find
|
|
|
|
int dstring_find (char val, dstring str);
|
|
|
|
|
|
|
|
// compare strings
|
|
|
|
int dstring_cmp (dstring str1, dstring str2);
|
|
|
|
|
|
|
|
// print str
|
|
|
|
int dstring_print (dstring str, FILE* file);
|
|
|
|
|
|
|
|
// append a char*
|
|
|
|
int dstring_append_str(char* str, dstring* output);
|
|
|
|
|
|
|
|
// convert to char*
|
|
|
|
int dstring_to_str(dstring input, char** output);
|
|
|
|
// noinit (changes the size of input if needed)
|
|
|
|
char* dstring_to_str_noinit(dstring* input);
|
|
|
|
|
|
|
|
// convert from char*
|
|
|
|
int str_to_dstring(char* str, dstring* output);
|
2023-11-03 16:04:53 -04:00
|
|
|
int str_to_dstring_noinit(char* str, dstring* output);
|
2023-11-03 12:25:02 -04:00
|
|
|
|
|
|
|
// compare a dstring and a char*
|
|
|
|
int dstring_cmp_str(dstring dstring, char* str);
|
|
|
|
|
|
|
|
// format strings
|
|
|
|
int dstring_snprintf(dstring* output, char* fmt, ...);
|
|
|
|
|
|
|
|
#endif
|