Objectively
Object oriented framework for C.
Loading...
Searching...
No Matches
String.h File Reference

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
 UTF-8 strings. More...
 

Typedefs

typedef wchar_t Unicode
 The Unicode type.
 

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.
 

Detailed Description

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 994 of file String.c.

994 {
995 static Class *clazz;
996 static Once once;
997
998 do_once(&once, {
999 clazz = _initialize(&(const ClassDef) {
1000 .name = "String",
1001 .superclass = _Object(),
1002 .instanceSize = sizeof(String),
1003 .interfaceSize = sizeof(StringInterface),
1004 .initialize = initialize,
1005 });
1006 });
1007
1008 return clazz;
1009}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:151
Class * _Object(void)
Definition Object.c:136
static void initialize(Class *clazz)
Definition String.c:930
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:90
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 1091 of file String.c.

1091 {
1092
1093 assert(s);
1094 while (isspace(*s)) {
1095 s++;
1096 }
1097
1098 char *trimmed = strdup(s);
1099 assert(trimmed);
1100
1101 char *end = trimmed + strlen(trimmed);
1102 if (end > trimmed) {
1103 while (isspace(*(--end))) {
1104 *end = '\0';
1105 }
1106 }
1107
1108 return trimmed;
1109}