Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <ctype.h>
27#include <wctype.h>
28#include <stdarg.h>
29
30#include <Objectively/Array.h>
31#include <Objectively/Data.h>
32
41typedef wchar_t Unicode;
42
56
57typedef struct StringInterface StringInterface;
58
69struct String {
70
75
80 StringInterface *interface;
81
85 char *chars;
86
90 size_t length;
91
96 size_t capacity;
97};
98
99
103struct StringInterface {
104
108 ObjectInterface objectInterface;
109
119 void (*appendBytes)(String *self, const uint8_t *bytes, size_t length, StringEncoding encoding);
120
128 void (*appendCharacters)(String *self, const char *chars);
129
137 void (*appendFormat)(String *self, const char *fmt, ...);
138
146 void (*appendString)(String *self, const String *string);
147
156 void (*appendVaList)(String *self, const char *fmt, va_list args);
157
167 Order (*compareTo)(const String *self, const String *other, const Range range);
168
177 Array *(*componentsSeparatedByCharacters)(const String *self, const char *chars);
178
187 Array *(*componentsSeparatedByString)(const String *self, const String *string);
188
196 void (*deleteCharactersInRange)(String *self, const Range range);
197
206 Data *(*getData)(const String *self, StringEncoding encoding);
207
216 bool (*hasPrefix)(const String *self, const String *prefix);
217
226 bool (*hasSuffix)(const String *self, const String *suffix);
227
235 String *(*init)(String *self);
236
247 String *(*initWithBytes)(String *self, const uint8_t *bytes, size_t length, StringEncoding encoding);
248
257 String *(*initWithCapacity)(String *self, size_t capacity);
258
267 String *(*initWithCharacters)(String *self, const char *chars);
268
278 String *(*initWithContentsOfFile)(String *self, const char *path, StringEncoding encoding);
279
289 String *(*initWithData)(String *self, const Data *data, StringEncoding encoding);
290
299 String *(*initWithFormat)(String *self, const char *fmt, ...);
300
311 String *(*initWithMemory)(String *self, const ident mem, size_t length);
312
321 String *(*initWithString)(String *self, const String *string);
322
333 String *(*initWithVaList)(String *self, const char *fmt, va_list args);
334
343 void (*insertCharactersAtIndex)(String *self, const char *chars, size_t index);
344
353 void (*insertStringAtIndex)(String *self, const String *string, size_t index);
354
361 String *(*lowercaseString)(const String *self);
362
372 Range (*rangeOfCharacters)(const String *self, const char *chars, const Range range);
373
383 Range (*rangeOfString)(const String *self, const String *string, const Range range);
384
393 void (*replaceCharactersInRange)(String *self, const Range range, const char *chars);
394
403 void (*replaceOccurrencesOfCharacters)(String *self, const char *chars, const char *replacement);
404
414 void (*replaceOccurrencesOfCharactersInRange)(String *self, const char *chars, const Range range, const char *replacement);
415
424 void (*replaceOccurrencesOfString)(String *self, const String *string, const String *replacement);
425
435 void (*replaceOccurrencesOfStringInRange)(String *self, const String *string, const Range range, const String *replacement);
436
445 void (*replaceStringInRange)(String *self, const Range range, const String *string);
446
454 void (*setCharacters)(String *self, const char *chars);
455
463 void (*setFormat)(String *self, const char *fmt, ...);
464
472 void (*setLength)(String *self, size_t length);
473
481 void (*setString)(String *self, const String *string);
482
490 String *(*string)(void);
491
502 String *(*stringWithBytes)(const uint8_t *bytes, size_t length, StringEncoding encoding);
503
512 String *(*stringWithCapacity)(size_t capacity);
513
522 String *(*stringWithCharacters)(const char *chars);
523
533 String *(*stringWithContentsOfFile)(const char *path, StringEncoding encoding);
534
544 String *(*stringWithData)(const Data *data, StringEncoding encoding);
545
554 String *(*stringWithFormat)(const char *fmt, ...);
555
566 String *(*stringWithMemory)(const ident mem, size_t length);
567
576 String *(*substring)(const String *self, const Range range);
577
584 void (*trim)(String *self);
585
593 String *(*trimmedString)(const String *self);
594
601 String *(*uppercaseString)(const String *self);
602
612 bool (*writeToFile)(const String *self, const char *path, StringEncoding encoding);
613
614};
615
623
631
638
647
654OBJECTIVELY_EXPORT String *str(const char *fmt, ...);
655
661OBJECTIVELY_EXPORT char *strtrim(const char *s);
Arrays.
static Data * data(void)
Definition Data.c:286
Data buffers.
const char * NameForStringEncoding(StringEncoding encoding)
Definition String.c:1019
String * str(const char *fmt,...)
Definition String.c:1084
StringEncoding StringEncodingForName(const char *name)
Definition String.c:1043
Order StringCompare(const ident a, const ident b)
Definition String.c:1066
StringEncoding
Character encodings for Strings.
Definition String.h:46
@ STRING_ENCODING_LATIN1
Definition String.h:48
@ STRING_ENCODING_WCHAR
Definition String.h:54
@ STRING_ENCODING_UTF32
Definition String.h:52
@ STRING_ENCODING_MACROMAN
Definition String.h:50
@ STRING_ENCODING_UTF16
Definition String.h:51
@ STRING_ENCODING_ASCII
Definition String.h:47
@ STRING_ENCODING_LATIN2
Definition String.h:49
@ STRING_ENCODING_UTF8
Definition String.h:53
OBJECTIVELY_EXPORT Class * _String(void)
Definition String.c:999
OBJECTIVELY_EXPORT char * strtrim(const char *s)
Copies the given null-terminated C string, trimming leading and trailing whitespace.
Definition String.c:1097
wchar_t Unicode
The Unicode type.
Definition String.h:41
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
#define OBJECTIVELY_EXPORT
Definition Types.h:36
Order
Comparison constants.
Definition Types.h:70
Arrays.
Definition Array.h:56
The runtime representation of a Class.
Definition Class.h:95
Data buffers.
Definition Data.h:50
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
A location and length into contiguous collections.
Definition Types.h:54
UTF-8 strings.
Definition String.h:69
char * chars
The backing null-terminated UTF-8 encoded character array.
Definition String.h:85
StringInterface * interface
The interface.
Definition String.h:80
size_t length
The length of the String in bytes.
Definition String.h:90
Object object
The superclass.
Definition String.h:74