Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Data Structures | Typedefs | Enumerations | Functions
String.h File Reference

Immutable UTF-8 strings. More...

#include <ctype.h>
#include <wctype.h>
#include <stdarg.h>
#include <Objectively/Array.h>
#include <Objectively/Data.h>

Go to the source code of this file.

Data Structures

struct  String
 Immutable UTF-8 strings. More...
 

Typedefs

typedef wchar_t Unicode
 The Unicode type. More...
 

Enumerations

enum  StringEncoding {
  STRING_ENCODING_ASCII = 1 , STRING_ENCODING_LATIN1 , STRING_ENCODING_LATIN2 , STRING_ENCODING_MACROMAN ,
  STRING_ENCODING_UTF16 , STRING_ENCODING_UTF32 , STRING_ENCODING_UTF8 , STRING_ENCODING_WCHAR
}
 Character encodings for Strings. More...
 

Functions

OBJECTIVELY_EXPORT Class_String (void)
 
OBJECTIVELY_EXPORT char * strtrim (const char *s)
 Copies the given null-terminated C string, trimming leading and trailing whitespace. More...
 

Detailed Description

Immutable UTF-8 strings.

Definition in file String.h.

Typedef Documentation

◆ Unicode

typedef wchar_t Unicode

The Unicode type.

Definition at line 41 of file String.h.

Enumeration Type Documentation

◆ StringEncoding

Character encodings for Strings.

Enumerator
STRING_ENCODING_ASCII 
STRING_ENCODING_LATIN1 
STRING_ENCODING_LATIN2 
STRING_ENCODING_MACROMAN 
STRING_ENCODING_UTF16 
STRING_ENCODING_UTF32 
STRING_ENCODING_UTF8 
STRING_ENCODING_WCHAR 

Definition at line 46 of file String.h.

46 {
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

Function Documentation

◆ _String()

OBJECTIVELY_EXPORT Class * _String ( void  )

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 * _Object(void)
The Object archetype.
Definition: Object.c:136
Immutable UTF-8 strings.
Definition: String.h:69

◆ strtrim()

OBJECTIVELY_EXPORT char * strtrim ( const char *  s)

Copies the given null-terminated C string, trimming leading and trailing whitespace.

Parameters
sA null-terminated C string.
Returns
A trimmed copy of str which must be freed by the caller.

Definition at line 752 of file String.c.

752 {
753
754 assert(s);
755 while (isspace(*s)) {
756 s++;
757 }
758
759 char *trimmed = strdup(s);
760 assert(trimmed);
761
762 char *end = trimmed + strlen(trimmed);
763 if (end > trimmed) {
764 while (isspace(*(--end))) {
765 *end = '\0';
766 }
767 }
768
769 return trimmed;
770}