Objectively
Ultra-lightweight object oriented framework for GNU 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 999 of file String.c.

999 {
1000 static Class *clazz;
1001 static Once once;
1002
1003 do_once(&once, {
1004 clazz = _initialize(&(const ClassDef) {
1005 .name = "String",
1006 .superclass = _Object(),
1007 .instanceSize = sizeof(String),
1008 .interfaceOffset = offsetof(String, interface),
1009 .interfaceSize = sizeof(StringInterface),
1011 });
1012 });
1013
1014 return clazz;
1015}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
Class * _Object(void)
Definition Object.c:136
static void initialize(Class *clazz)
Definition String.c:935
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
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 1097 of file String.c.

1097 {
1098
1099 assert(s);
1100 while (isspace(*s)) {
1101 s++;
1102 }
1103
1104 char *trimmed = strdup(s);
1105 assert(trimmed);
1106
1107 char *end = trimmed + strlen(trimmed);
1108 if (end > trimmed) {
1109 while (isspace(*(--end))) {
1110 *end = '\0';
1111 }
1112 }
1113
1114 return trimmed;
1115}