Change string_contains
[libstring.git] / src / libstring.h
blobca6187bfe6505da9eebb9a3d0be24aa1cbbf18f4
1 /*
2 * libstring
3 * https://github.com/carmesim/libstring
5 * Copyright (c) 2020 Vinícius R. Miguel, Ivan dos Santos Muniz
6 * <vinicius.miguel at unifesp.br>
7 * <ivan.muniz at unifesp.br>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
28 #include <stdbool.h>
29 #include <stdlib.h>
31 /* Type definitions */
33 struct cstr
35 char * value;
36 size_t size;
37 size_t reserved;
38 // enum encoding; libstring 2.0 or more
41 typedef struct cstr cstr_t;
43 /*** Function prototypes ***/
44 // Initialization and memory
45 cstr_t * string_init(const char * origin);
46 /* Attempts to reserve `capacity` bytes onto the string, returns true if possible. */
47 bool string_reserve(cstr_t *str, size_t capacity); // def, tested, needs one more test case
48 bool string_resize(cstr_t *str, size_t new_size); // undef
49 bool string_free(cstr_t * str); // undef
50 /* Frees all allocated strings */
51 void string_free_all(void); // def, tested, unfinished
53 // Utility functions
54 int string_compare(cstr_t * str1, cstr_t * str2); // undef, Follows C++ standard
55 cstr_t * string_concat(cstr_t * str1, cstr_t * str2); // undef, returns str1 + str2
56 size_t string_concat_to(cstr_t * str1, cstr_t * str2); // undef, str1 = str1 + str2
57 bool string_ends_with_x(cstr_t * str, cstr_t * x); // undef
58 char string_get_char_at(cstr_t * str, size_t pos); // undef, bound-checking
59 size_t string_index_of(cstr_t *str, char c); // undef
60 size_t string_last_index_of(cstr_t *str, char c); // undef
61 cstr_t * string_left(cstr_t * str, size_t length); // undef
62 cstr_t * string_mid(cstr_t * str, size_t pos, size_t length); // undef
63 size_t string_replace_char(cstr_t *str, char before, char after); // def, tested, see related to-do inside function.
64 cstr_t * string_reverse(cstr_t * str); // undef
65 cstr_t string_right(cstr_t * str, size_t length); // undef
66 bool string_set_char_at(cstr_t * str, size_t pos); // undef
67 size_t string_size(cstr_t * str); // undef, TODO: unneeded? size is accessible within the string
68 bool string_starts_with_x(cstr_t * str, cstr_t * x); // undef
69 bool string_swap(cstr_t * str1, cstr_t * str2); // def, tested
70 int string_to_int(cstr_t * str); // undef
72 cstr_t * string_to_lower_case(cstr_t * origin); // def, tested
73 cstr_t * string_to_upper_case(cstr_t * origin); // def, tested
74 bool string_contains(cstr_t * str1, const char * str2); // def, tested
75 size_t string_replace(cstr_t * str, const char * new_val); // def, tested
77 /* Implement if possible (not a priority atm) */
78 //cstr_t string_tokenize(cstr_t * str, char delim); // Que inferno vai ser isso aqui.
79 //stol - Convert string to long int
80 //stoul - Convert string to unsigned integer
81 //stoll - Convert string to long long
82 //stoull - Convert string to unsigned long long
83 //stof - Convert string to float
84 //stod - Convert string to double (function template )