Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Properties | Methods | Protected Attributes | Related Functions
String Struct Reference

#include <String.h>

Overview

Immutable UTF-8 strings.

Remarks
Because Strings are encoded using UTF-8, they must not be treated as ASCII C strings. That is, a single Unicode code point will often span multiple chars. Be mindful of this when executing Range operations.
Strings are locale-ready, but Objectively does not enable locale by default. Call setlocale to enable localization.

Definition at line 69 of file String.h.

Inheritance diagram for String:
Object MutableString

Properties

char * chars
 The backing null-terminated UTF-8 encoded character array. More...
 
size_t length
 The length of the String in bytes. More...
 
Object object
 The superclass. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_String (void)
 The String archetype. More...
 
Order compareTo (const String *self, const String *other, const Range range)
 Compares this String lexicographically to another. More...
 
ArraycomponentsSeparatedByCharacters (const String *self, const char *chars)
 Returns the components of this String that were separated by chars. More...
 
ArraycomponentsSeparatedByString (const String *self, const String *string)
 Returns the components of this String that were separated by string. More...
 
DatagetData (const String *self, StringEncoding encoding)
 Returns a Data with this String's contents in the given encoding. More...
 
_Bool hasPrefix (const String *self, const String *prefix)
 Checks this String for the given prefix. More...
 
_Bool hasSuffix (const String *self, const String *suffix)
 Checks this String for the given suffix. More...
 
StringinitWithBytes (String *self, const uint8_t *bytes, size_t length, StringEncoding encoding)
 Initializes this String by decoding length of bytes. More...
 
StringinitWithCharacters (String *self, const char *chars)
 Initializes this String by copying chars. More...
 
StringinitWithContentsOfFile (String *self, const char *path, StringEncoding encoding)
 Initializes this String with the contents of the FILE at path. More...
 
StringinitWithData (String *self, const Data *data, StringEncoding encoding)
 Initializes this String with the given Data. More...
 
StringinitWithFormat (String *self, const char *fmt,...)
 Initializes this String with the specified format string. More...
 
StringinitWithMemory (String *self, const ident mem, size_t length)
 Initializes this String with the specified buffer. More...
 
StringinitWithVaList (String *self, const char *fmt, va_list args)
 Initializes this String with the specified arguments list. More...
 
StringlowercaseString (const String *self)
 
MutableStringmutableCopy (const String *self)
 
Range rangeOfCharacters (const String *self, const char *chars, const Range range)
 Finds and returns the first occurrence of chars in this String. More...
 
Range rangeOfString (const String *self, const String *string, const Range range)
 Finds and returns the first occurrence of string in this String. More...
 
StringstringWithBytes (const uint8_t *bytes, size_t length, StringEncoding encoding)
 Returns a new String by decoding length of bytes to UTF-8. More...
 
StringstringWithCharacters (const char *chars)
 Returns a new String by copying chars. More...
 
StringstringWithContentsOfFile (const char *path, StringEncoding encoding)
 Returns a new String with the contents of the FILE at path. More...
 
StringstringWithData (const Data *data, StringEncoding encoding)
 Returns a new String with the the given Data. More...
 
StringstringWithFormat (const char *fmt)
 Returns a new String with the given format string. More...
 
StringstringWithMemory (const ident mem, size_t length)
 Returns a new String with the given buffer. More...
 
Stringsubstring (const String *string, const Range range)
 Creates a new String from a subset of this one. More...
 
StringtrimmedString (const String *self)
 Creates a copy of this String with leading and trailing whitespace removed. More...
 
StringuppercaseString (const String *self)
 
_Bool writeToFile (const String *self, const char *path, StringEncoding encoding)
 Writes this String to path. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

StringInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Related Functions

OBJECTIVELY_EXPORT MutableStringmstr (const char *fmt,...)
 A convenience function for instantiating MutableStrings. More...
 
OBJECTIVELY_EXPORT const char * NameForStringEncoding (StringEncoding encoding)
 
OBJECTIVELY_EXPORT Stringstr (const char *fmt,...)
 A convenience function for instantiating Strings. More...
 
OBJECTIVELY_EXPORT Order StringCompare (const ident a, const ident b)
 A Comparator for sorting Strings. More...
 
OBJECTIVELY_EXPORT StringEncoding StringEncodingForName (const char *name)
 

Property Details

◆ chars

char* String::chars

The backing null-terminated UTF-8 encoded character array.

Definition at line 85 of file String.h.

◆ interface

StringInterface* String::interface
protected

The interface.

Definition at line 80 of file String.h.

◆ length

size_t String::length

The length of the String in bytes.

Definition at line 90 of file String.h.

◆ object

Object String::object

The superclass.

Definition at line 74 of file String.h.

Method Details

◆ _String()

Class * _String ( void  )

The String archetype.

Returns
The String Class.

Definition at line 654 of file String.c.

654 {
655 static Class *clazz;
656 static Once once;
657
658 do_once(&once, {
659 clazz = _initialize(&(const ClassDef) {
660 .name = "String",
661 .superclass = _Object(),
662 .instanceSize = sizeof(String),
663 .interfaceOffset = offsetof(String, interface),
664 .interfaceSize = sizeof(StringInterface),
666 });
667 });
668
669 return clazz;
670}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: String.c:613
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
Immutable UTF-8 strings.
Definition: String.h:69
StringInterface * interface
The interface.
Definition: String.h:80

◆ compareTo()

Order compareTo ( const String self,
const String other,
const Range  range 
)

Compares this String lexicographically to another.

Parameters
selfThe String.
otherThe String to compare to.
rangeThe character Range to compare.
Returns
The ordering of this String compared to other.

Definition at line 163 of file String.c.

163 {
164
165 assert(range.location + range.length <= self->length);
166
167 if (other) {
168 const int i = strncmp(self->chars + range.location, other->chars, range.length);
169 if (i == 0) {
170 return OrderSame;
171 }
172 if (i > 0) {
173 return OrderDescending;
174 }
175 }
176
177 return OrderAscending;
178}
@ OrderSame
Definition: Types.h:72
@ OrderDescending
Definition: Types.h:73
@ OrderAscending
Definition: Types.h:71
ssize_t location
The location.
Definition: Types.h:59
size_t length
The length.
Definition: Types.h:64
char * chars
The backing null-terminated UTF-8 encoded character array.
Definition: String.h:85
size_t length
The length of the String in bytes.
Definition: String.h:90

◆ componentsSeparatedByCharacters()

Array * componentsSeparatedByCharacters ( const String self,
const char *  chars 
)

Returns the components of this String that were separated by chars.

Parameters
selfThe String.
charsThe separating characters.
Returns
An Array of substrings that were separated by chars.

Definition at line 184 of file String.c.

184 {
185
186 assert(chars);
187
188 MutableArray *components = $(alloc(MutableArray), init);
189
190 Range search = { 0, self->length };
191 Range result = $(self, rangeOfCharacters, chars, search);
192
193 while (result.length) {
194 search.length = result.location - search.location;
195
196 String *component = $(self, substring, search);
197 $(components, addObject, component);
198 release(component);
199
200 search.location = result.location + result.length;
201 search.length = self->length - search.location;
202
203 result = $(self, rangeOfCharacters, chars, search);
204 }
205
206 String *component = $(self, substring, search);
207 $(components, addObject, component);
208 release(component);
209
210 return (Array *) components;
211}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition: Class.c:196
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
static void addObject(MutableArray *self, const ident obj)
Definition: MutableArray.c:99
Immutable arrays.
Definition: Array.h:56
Mutable arrays.
Definition: MutableArray.h:40
Object * init(Object *self)
Initializes this Object.
Definition: Object.c:83
A location and length into contiguous collections.
Definition: Types.h:54
String * substring(const String *string, const Range range)
Creates a new String from a subset of this one.
Definition: String.c:539
Range rangeOfCharacters(const String *self, const char *chars, const Range range)
Finds and returns the first occurrence of chars in this String.
Definition: String.c:441

◆ componentsSeparatedByString()

Array * componentsSeparatedByString ( const String self,
const String string 
)

Returns the components of this String that were separated by string.

Parameters
selfThe String.
stringThe separating String.
Returns
An Array of substrings that were separated by string.

Definition at line 217 of file String.c.

217 {
218
219 assert(string);
220
222}
static MutableString * string(void)
Array * componentsSeparatedByCharacters(const String *self, const char *chars)
Returns the components of this String that were separated by chars.
Definition: String.c:184

◆ getData()

Data * getData ( const String self,
StringEncoding  encoding 
)

Returns a Data with this String's contents in the given encoding.

Parameters
selfThe String.
encodingThe desired StringEncoding.
Returns
A Data with this String's contents in the given encoding.

Definition at line 228 of file String.c.

228 {
229
230 Transcode trans = {
231 .to = encoding,
232 .from = STRING_ENCODING_UTF8,
233 .in = self->chars,
234 .length = self->length,
235 .out = calloc(self->length, sizeof(Unicode) / sizeof(char)),
236 .size = self->length * sizeof(Unicode)
237 };
238
239 assert(trans.out);
240
241 const size_t size = transcode(&trans);
242 assert(size <= trans.size);
243
244 return $$(Data, dataWithMemory, trans.out, size);
245}
static Data * dataWithMemory(ident mem, size_t length)
Definition: Data.c:136
static size_t transcode(Transcode *trans)
Transcodes input from one character encoding to another via iconv.
Definition: String.c:133
@ STRING_ENCODING_UTF8
Definition: String.h:53
wchar_t Unicode
The Unicode type.
Definition: String.h:41
Immutable data buffers.
Definition: Data.h:50
Character transcoding context for iconv.
Definition: String.c:119
char * out
Definition: String.c:124
size_t size
Definition: String.c:125
StringEncoding to
Definition: String.c:120

◆ hasPrefix()

_Bool hasPrefix ( const String self,
const String prefix 
)

Checks this String for the given prefix.

Parameters
selfThe String.
prefixThe Prefix to check.
Returns
True if this String starts with prefix, false otherwise.

Definition at line 251 of file String.c.

251 {
252
253 if (prefix->length > self->length) {
254 return false;
255 }
256
257 Range range = { 0, prefix->length };
258 return $(self, compareTo, prefix, range) == OrderSame;
259}
Order compareTo(const String *self, const String *other, const Range range)
Compares this String lexicographically to another.
Definition: String.c:163

◆ hasSuffix()

_Bool hasSuffix ( const String self,
const String suffix 
)

Checks this String for the given suffix.

Parameters
selfThe String.
suffixThe suffix to check.
Returns
True if this String ends with suffix, false otherwise.

Definition at line 265 of file String.c.

265 {
266
267 if (suffix->length > self->length) {
268 return false;
269 }
270
271 Range range = { self->length - suffix->length, suffix->length };
272 return $(self, compareTo, suffix, range) == OrderSame;
273}

◆ initWithBytes()

String * initWithBytes ( String self,
const uint8_t *  bytes,
size_t  length,
StringEncoding  encoding 
)

Initializes this String by decoding length of bytes.

Parameters
selfThe String.
bytesThe bytes.
lengthThe length of bytes to decode.
encodingThe character encoding.
Returns
The initialized String, or NULL on error.

Definition at line 279 of file String.c.

279 {
280
281 if (bytes) {
282
283 Transcode trans = {
285 .from = encoding,
286 .in = (char *) bytes,
287 .length = length,
288 .out = calloc(length * sizeof(Unicode) + 1, sizeof(char)),
289 .size = length * sizeof(Unicode) + 1
290 };
291
292 assert(trans.out);
293
294 const size_t size = transcode(&trans);
295 assert(size < trans.size);
296
297 ident mem = realloc(trans.out, size + 1);
298 assert(mem);
299
300 return $(self, initWithMemory, mem, size);
301 }
302
303 return $(self, initWithMemory, NULL, 0);
304}
void * ident
The identity type, similar to Objective-C id.
Definition: Types.h:49
String * initWithMemory(String *self, const ident mem, size_t length)
Initializes this String with the specified buffer.
Definition: String.c:372

◆ initWithCharacters()

String * initWithCharacters ( String self,
const char *  chars 
)

Initializes this String by copying chars.

Parameters
selfThe String.
charsThe null-terminated, UTF-8 encoded C string.
Returns
The initialized String, or NULL on error.

Definition at line 310 of file String.c.

310 {
311
312 if (chars) {
313
314 ident mem = strdup(chars);
315 assert(mem);
316
317 const size_t length = strlen(chars);
318 return $(self, initWithMemory, mem, length);
319 }
320
321 return $(self, initWithMemory, NULL, 0);
322}

◆ initWithContentsOfFile()

String * initWithContentsOfFile ( String self,
const char *  path,
StringEncoding  encoding 
)

Initializes this String with the contents of the FILE at path.

Parameters
selfThe String.
pathThe path of the file to load.
encodingThe character encoding.
Returns
The initialized String, or NULL on error.

Definition at line 328 of file String.c.

328 {
329
330 Data *data = $$(Data, dataWithContentsOfFile, path);
331 if (data) {
332 self = $(self, initWithData, data, encoding);
333 } else {
334 self = $(self, initWithMemory, NULL, 0);
335 }
336 release(data);
337
338 return self;
339}
static Data * dataWithContentsOfFile(const char *path)
Definition: Data.c:127
static MutableData * data(void)
Definition: MutableData.c:75
String * initWithData(String *self, const Data *data, StringEncoding encoding)
Initializes this String with the given Data.
Definition: String.c:345

◆ initWithData()

String * initWithData ( String self,
const Data data,
StringEncoding  encoding 
)

Initializes this String with the given Data.

Parameters
selfThe String.
dataThe Data object.
encodingThe character encoding.
Returns
The initialized String, or NULL on error.

Definition at line 345 of file String.c.

345 {
346
347 assert(data);
348
349 return $(self, initWithBytes, data->bytes, data->length, encoding);
350}
size_t length
The length of bytes.
Definition: Data.h:76
uint8_t * bytes
The bytes.
Definition: Data.h:66
String * initWithBytes(String *self, const uint8_t *bytes, size_t length, StringEncoding encoding)
Initializes this String by decoding length of bytes.
Definition: String.c:279

◆ initWithFormat()

String * initWithFormat ( String self,
const char *  fmt,
  ... 
)

Initializes this String with the specified format string.

Parameters
selfThe String.
fmtThe format string.
Returns
The initialized String, or NULL on error.

Definition at line 356 of file String.c.

356 {
357
358 va_list args;
359 va_start(args, fmt);
360
361 self = $(self, initWithVaList, fmt, args);
362
363 va_end(args);
364
365 return self;
366}
String * initWithVaList(String *self, const char *fmt, va_list args)
Initializes this String with the specified arguments list.
Definition: String.c:390

◆ initWithMemory()

String * initWithMemory ( String self,
const ident  mem,
size_t  length 
)

Initializes this String with the specified buffer.

Parameters
selfThe String.
memThe dynamically allocated null-terminated, UTF-8 encoded buffer.
lengthThe length of mem in printable characters.
Returns
The initialized String, or NULL on error.
Remarks
The memory will be freed when this String is deallocated.

Definition at line 372 of file String.c.

372 {
373
374 self = (String *) super(Object, self, init);
375 if (self) {
376
377 if (mem) {
378 self->chars = (char *) mem;
379 self->length = length;
380 }
381 }
382
383 return self;
384}
#define super(type, obj, method,...)
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46

◆ initWithVaList()

String * initWithVaList ( String self,
const char *  fmt,
va_list  args 
)

Initializes this String with the specified arguments list.

Parameters
selfThe String.
fmtThe format string.
argsThe format arguments.
Returns
The initialized String, or NULL on error.
See also
vasprintf(3)

Definition at line 390 of file String.c.

390 {
391
392 self = (String *) super(Object, self, init);
393 if (self) {
394
395 if (fmt) {
396 const int len = vasprintf(&self->chars, fmt, args);
397 assert(len >= 0);
398
399 self->length = len;
400 }
401 }
402
403 return self;
404}

◆ lowercaseString()

String * lowercaseString ( const String self)
Parameters
selfThe String.
Returns
A lowercase representation of this String.

Definition at line 410 of file String.c.

410 {
411
413 assert(data);
414
415 const size_t codepoints = data->length / sizeof(Unicode);
416 Unicode *unicode = (Unicode *) data->bytes;
417
418 for (size_t i = 0; i < codepoints; i++, unicode++) {
419 *unicode = towlower(*unicode);
420 }
421
423
424 release(data);
425 return lowercase;
426}
@ STRING_ENCODING_WCHAR
Definition: String.h:54
String * stringWithData(const Data *data, StringEncoding encoding)
Returns a new String with the the given Data.
Definition: String.c:505
Data * getData(const String *self, StringEncoding encoding)
Returns a Data with this String's contents in the given encoding.
Definition: String.c:228

◆ mutableCopy()

MutableString * mutableCopy ( const String self)
Parameters
selfThe String.
Returns
A MutableString with the contents of this String.

Definition at line 432 of file String.c.

432 {
433
434 return $(alloc(MutableString), initWithString, self);
435}
static MutableString * initWithString(MutableString *self, const String *string)
Mutable UTF-8 strings.
Definition: MutableString.h:40

◆ rangeOfCharacters()

Range rangeOfCharacters ( const String self,
const char *  chars,
const Range  range 
)

Finds and returns the first occurrence of chars in this String.

Parameters
selfThe String.
charsThe characters to search for.
rangeThe Range in which to search.
Returns
A Range specifying the first occurrence of chars in this String.

Definition at line 441 of file String.c.

441 {
442
443 assert(chars);
444 assert(range.location > -1);
445 assert(range.length > 0);
446 assert(range.location + range.length <= self->length);
447
448 Range match = { -1, 0 };
449 const size_t len = strlen(chars);
450
451 const char *str = self->chars + range.location;
452 for (size_t i = 0; i < range.length; i++, str++) {
453 if (strncmp(str, chars, len) == 0) {
454 match.location = range.location + i;
455 match.length = len;
456 break;
457 }
458 }
459
460 return match;
461}
OBJECTIVELY_EXPORT String * str(const char *fmt,...)
A convenience function for instantiating Strings.
Definition: String.c:739

◆ rangeOfString()

Range rangeOfString ( const String self,
const String string,
const Range  range 
)

Finds and returns the first occurrence of string in this String.

Parameters
selfThe String.
stringThe String to search for.
rangeThe Range in which to search.
Returns
A Range specifying the first occurrence of string in this String.

Definition at line 467 of file String.c.

467 {
468
469 assert(string);
470
471 return $(self, rangeOfCharacters, string->chars, range);
472}

◆ stringWithBytes()

String * stringWithBytes ( const uint8_t *  bytes,
size_t  length,
StringEncoding  encoding 
)

Returns a new String by decoding length of bytes to UTF-8.

Parameters
bytesThe bytes.
lengthThe length of bytes to copy.
encodingThe character encoding.
Returns
The new String, or NULL on error.

Definition at line 478 of file String.c.

478 {
479
480 return $(alloc(String), initWithBytes, bytes, length, encoding);
481}

◆ stringWithCharacters()

String * stringWithCharacters ( const char *  chars)

Returns a new String by copying chars.

Parameters
charsThe null-terminated UTF-8 encoded C string.
Returns
The new String, or NULL on error.

Definition at line 487 of file String.c.

487 {
488
490}
String * initWithCharacters(String *self, const char *chars)
Initializes this String by copying chars.
Definition: String.c:310

◆ stringWithContentsOfFile()

String * stringWithContentsOfFile ( const char *  path,
StringEncoding  encoding 
)

Returns a new String with the contents of the FILE at path.

Parameters
pathA path name.
encodingThe character encoding.
Returns
The new String, or NULL on error.

Definition at line 496 of file String.c.

496 {
497
498 return $(alloc(String), initWithContentsOfFile, path, encoding);
499}
String * initWithContentsOfFile(String *self, const char *path, StringEncoding encoding)
Initializes this String with the contents of the FILE at path.
Definition: String.c:328

◆ stringWithData()

String * stringWithData ( const Data data,
StringEncoding  encoding 
)

Returns a new String with the the given Data.

Parameters
dataA Data.
encodingThe character encoding.
Returns
The new String, or NULL on error.

Definition at line 505 of file String.c.

505 {
506
507 return $(alloc(String), initWithData, data, encoding);
508}

◆ stringWithFormat()

String * stringWithFormat ( const char *  fmt)

Returns a new String with the given format string.

Parameters
fmtThe format string.
Returns
The new String, or NULL on error.

◆ stringWithMemory()

String * stringWithMemory ( const ident  mem,
size_t  length 
)

Returns a new String with the given buffer.

Parameters
memA dynamically allocated, null-terminated UTF-8 encoded buffer.
lengthThe length of mem in bytes.
Returns
The new String, or NULL on error.
Remarks
The memory will be freed when the returned String is deallocated.

Definition at line 530 of file String.c.

530 {
531
532 return $(alloc(String), initWithMemory, mem, length);
533}

◆ substring()

String * substring ( const String self,
const Range  range 
)

Creates a new String from a subset of this one.

Parameters
selfThe String.
rangeThe character Range.
Returns
The new String.

Definition at line 539 of file String.c.

539 {
540
541 assert(range.location + range.length <= self->length);
542
543 ident mem = calloc(range.length + 1, sizeof(char));
544 assert(mem);
545
546 strncpy(mem, self->chars + range.location, range.length);
547
548 return $(alloc(String), initWithMemory, mem, range.length);
549}

◆ trimmedString()

String * trimmedString ( const String self)

Creates a copy of this String with leading and trailing whitespace removed.

Parameters
selfThe String.
Returns
The trimmed String.

Definition at line 555 of file String.c.

555 {
556
557 Range range = { .location = 0, .length = self->length };
558
559 while (isspace(self->chars[range.location])) {
560 range.location++;
561 range.length--;
562 }
563
564 while (isspace(self->chars[range.length])) {
565 range.length--;
566 }
567
568 return $(self, substring, range);
569}

◆ uppercaseString()

String * uppercaseString ( const String self)
Parameters
selfThe String.
Returns
An uppercase representation of this String.

Definition at line 575 of file String.c.

575 {
576
578 assert(data);
579
580 const size_t codepoints = data->length / sizeof(Unicode);
581 Unicode *unicode = (Unicode *) data->bytes;
582
583 for (size_t i = 0; i < codepoints; i++, unicode++) {
584 *unicode = towupper(*unicode);
585 }
586
588
589 release(data);
590 return uppercase;
591}

◆ writeToFile()

_Bool writeToFile ( const String self,
const char *  path,
StringEncoding  encoding 
)

Writes this String to path.

Parameters
selfThe String.
pathThe path of the file to write.
encodingThe character encoding.
Returns
true on success, false on error.

Definition at line 597 of file String.c.

597 {
598
599 Data *data = $(self, getData, encoding);
600 assert(data);
601
602 const _Bool success = $(data, writeToFile, path);
603
604 release(data);
605 return success;
606}
_Bool writeToFile(const String *self, const char *path, StringEncoding encoding)
Writes this String to path.
Definition: String.c:597

Related

◆ mstr()

OBJECTIVELY_EXPORT MutableString * mstr ( const char *  fmt,
  ... 
)
related

A convenience function for instantiating MutableStrings.

Parameters
fmtThe format string.
Returns
A new MutableString, or NULL on error.

Definition at line 379 of file MutableString.c.

379 {
380
381 MutableString *string = $$(MutableString, string);
382
383 va_list args;
384 va_start(args, fmt);
385
386 $(string, appendVaList, fmt, args);
387
388 va_end(args);
389 return string;
390}
static void appendVaList(MutableString *self, const char *fmt, va_list args)

◆ NameForStringEncoding()

OBJECTIVELY_EXPORT const char * NameForStringEncoding ( StringEncoding  encoding)
related
Parameters
encodingA StringEncoding.
Returns
The canonical name for the given encoding.

Definition at line 674 of file String.c.

674 {
675
676 switch (encoding) {
678 return "ASCII";
680 return "ISO-8859-1";
682 return "ISO-8859-2";
684 return "MacRoman";
686 return "UTF-16";
688 return "UTF-32";
690 return "UTF-8";
692 return "WCHAR_T";
693 }
694
695 return "ASCII";
696}
@ STRING_ENCODING_LATIN1
Definition: String.h:48
@ 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

◆ str()

OBJECTIVELY_EXPORT String * str ( const char *  fmt,
  ... 
)
related

A convenience function for instantiating Strings.

Parameters
fmtThe format string.
Returns
A new String, or NULL on error.

Definition at line 739 of file String.c.

739 {
740
741 va_list args;
742 va_start(args, fmt);
743
744 String *string = $(alloc(String), initWithVaList, fmt, args);
745 assert(string);
746
747 va_end(args);
748
749 return string;
750}

◆ StringCompare()

OBJECTIVELY_EXPORT Order StringCompare ( const ident  a,
const ident  b 
)
related

A Comparator for sorting Strings.

Parameters
aA String.
bA String.
Returns
The Order of a to b.

Definition at line 721 of file String.c.

721 {
722
723 if (a) {
724 if (b) {
725 const int i = strcmp(((String *) a)->chars, ((String *) b)->chars);
726 if (i == 0) {
727 return OrderSame;
728 }
729 if (i > 0) {
730 return OrderDescending;
731 }
732 } else {
733 return OrderDescending;
734 }
735 }
736 return OrderAscending;
737}

◆ StringEncodingForName()

OBJECTIVELY_EXPORT StringEncoding StringEncodingForName ( const char *  name)
related
Parameters
nameThe case-insensitive name of the encoding.
Returns
The StringEncoding for the given name.

Definition at line 698 of file String.c.

698 {
699
700 if (strcasecmp("ASCII", name) == 0) {
702 } else if (strcasecmp("ISO-8859-1", name) == 0) {
704 } else if (strcasecmp("ISO-8859-2", name) == 0) {
706 } else if (strcasecmp("MacRoman", name) == 0) {
708 } else if (strcasecmp("UTF-16", name) == 0) {
710 } else if (strcasecmp("UTF-32", name) == 0) {
712 } else if (strcasecmp("UTF-8", name) == 0) {
714 } else if (strcasecmp("WCHAR", name) == 0) {
716 }
717
719}

The documentation for this struct was generated from the following files: