39#if defined(__MINGW32__)
40#define towlower_l _towlower_l
41#define towupper_l _towupper_l
103 if (this->length == that->
length) {
105 const Range range = { 0, this->length };
142 assert(cd != (iconv_t ) -1);
144 char *in = trans->
in;
145 char *out = trans->
out;
147 size_t inBytesRemaining = trans->
length;
148 size_t outBytesRemaining = trans->
size;
150 const size_t ret = iconv(cd, &in, &inBytesRemaining, &out, &outBytesRemaining);
151 assert(ret != (
size_t ) -1);
153 int err = iconv_close(cd);
156 return trans->
size - outBytesRemaining;
210 return (
Array *) components;
242 assert(size <= trans.
size);
286 .in = (
char *) bytes,
288 .out = calloc(length *
sizeof(
Unicode) + 1,
sizeof(char)),
289 .size = length *
sizeof(
Unicode) + 1
295 assert(size < trans.
size);
297 ident mem = realloc(trans.
out, size + 1);
314 ident mem = strdup(chars);
317 const size_t length = strlen(chars);
378 self->
chars = (
char *) mem;
396 const int len = vasprintf(&self->
chars, fmt, args);
418 for (
size_t i = 0; i < codepoints; i++, unicode++) {
419 *unicode = towlower(*unicode);
448 Range match = { -1, 0 };
449 const size_t len = strlen(chars);
452 for (
size_t i = 0; i < range.
length; i++,
str++) {
453 if (strncmp(
str, chars, len) == 0) {
543 ident mem = calloc(range.
length + 1,
sizeof(
char));
583 for (
size_t i = 0; i < codepoints; i++, unicode++) {
584 *unicode = towupper(*unicode);
608#pragma mark - Class lifecycle
662 .instanceSize =
sizeof(
String),
663 .interfaceOffset = offsetof(
String, interface),
664 .interfaceSize =
sizeof(StringInterface),
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) {
725 const int i = strcmp(((
String *) a)->chars, ((
String *) b)->chars);
755 while (isspace(*s)) {
759 char *trimmed = strdup(s);
762 char *end = trimmed + strlen(trimmed);
764 while (isspace(*(--end))) {
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
int HashForCString(int hash, const char *string)
Accumulates the hash value of the null-terminated string into hash.
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
static size_t transcode(Transcode *trans)
Transcodes input from one character encoding to another via iconv.
char * strtrim(const char *s)
Copies the given null-terminated C string, trimming leading and trailing whitespace.
static void initialize(Class *clazz)
StringEncoding
Character encodings for Strings.
@ STRING_ENCODING_MACROMAN
wchar_t Unicode
The Unicode type.
void * ident
The identity type, similar to Objective-C id.
Order
Comparison constants.
#define do_once(once, block)
Executes the given block at most one time.
MutableArray * mutableCopy(const Array *self)
Array * initWithVaList(Array *self, va_list args)
Initializes this Array to contain the Objects in the NULL-terminated va_list.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
Data * initWithContentsOfFile(Data *self, const char *path)
Initializes this Data with the contents of the file at path.
Data * initWithMemory(Data *self, ident mem, size_t length)
Initializes this Data, taking ownership of the specified memory.
Data * dataWithMemory(ident mem, size_t length)
Returns a new Data, taking ownership of the specified memory.
Data * dataWithContentsOfFile(const char *path)
Returns a new Data with the contents of the file at path.
size_t length
The length of bytes.
uint8_t * bytes
The bytes.
_Bool writeToFile(const Data *self, const char *path)
Writes this Data to path.
Data * initWithBytes(Data *self, const uint8_t *bytes, size_t length)
Initializes this Data by copying length of bytes.
Order compareTo(const Date *self, const Date *other)
Compares this Date to another.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
MutableData * initWithData(MutableData *self, const Data *data)
Initializes this Data with the contents of data.
MutableData * data(void)
Returns a new MutableData.
MutableString * initWithString(MutableString *self, const String *string)
Initializes this MutableString with the contents of string.
MutableString * string(void)
Returns a new MutableString.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
String * description(const Object *self)
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
A location and length into contiguous collections.
ssize_t location
The location.
String * uppercaseString(const String *self)
char * chars
The backing null-terminated UTF-8 encoded character array.
Array * componentsSeparatedByCharacters(const String *self, const char *chars)
Returns the components of this String that were separated by chars.
_Bool writeToFile(const String *self, const char *path, StringEncoding encoding)
Writes this String to path.
String * stringWithMemory(const ident mem, size_t length)
Returns a new String with the given buffer.
Range rangeOfString(const String *self, const String *string, const Range range)
Finds and returns the first occurrence of string in this String.
size_t length
The length of the String in bytes.
String * lowercaseString(const String *self)
String * initWithCharacters(String *self, const char *chars)
Initializes this String by copying chars.
String * stringWithBytes(const uint8_t *bytes, size_t length, StringEncoding encoding)
Returns a new String by decoding length of bytes to UTF-8.
OBJECTIVELY_EXPORT StringEncoding StringEncodingForName(const char *name)
String * trimmedString(const String *self)
Creates a copy of this String with leading and trailing whitespace removed.
String * stringWithData(const Data *data, StringEncoding encoding)
Returns a new String with the the given Data.
String * stringWithFormat(const char *fmt)
Returns a new String with the given format string.
OBJECTIVELY_EXPORT const char * NameForStringEncoding(StringEncoding encoding)
Data * getData(const String *self, StringEncoding encoding)
Returns a Data with this String's contents in the given encoding.
String * substring(const String *string, const Range range)
Creates a new String from a subset of this one.
_Bool hasSuffix(const String *self, const String *suffix)
Checks this String for the given suffix.
String * initWithContentsOfFile(String *self, const char *path, StringEncoding encoding)
Initializes this String with the contents of the FILE at path.
Range rangeOfCharacters(const String *self, const char *chars, const Range range)
Finds and returns the first occurrence of chars in this String.
MutableString * mutableCopy(const String *self)
Class * _String(void)
The String archetype.
OBJECTIVELY_EXPORT String * str(const char *fmt,...)
A convenience function for instantiating Strings.
String * stringWithContentsOfFile(const char *path, StringEncoding encoding)
Returns a new String with the contents of the FILE at path.
String * stringWithCharacters(const char *chars)
Returns a new String by copying chars.
OBJECTIVELY_EXPORT Order StringCompare(const ident a, const ident b)
A Comparator for sorting Strings.
Array * componentsSeparatedByString(const String *self, const String *string)
Returns the components of this String that were separated by string.
_Bool hasPrefix(const String *self, const String *prefix)
Checks this String for the given prefix.
Character transcoding context for iconv.