src/util/string.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef UTIL_STRING_H
7#define UTIL_STRING_H
8
9#include "util/common.h"
10
11#ifndef HAVE_STRNDUP
12// This is sometimes a macro
13char* strndup(const char* start, size_t len);
14#endif
15
16#ifndef HAVE_STRDUP
17char* strdup(const char* str);
18#endif
19
20char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);
21bool endswith(const char* restrict s1, const char* restrict end);
22
23size_t toUtf8(uint32_t unichar, char* buffer);
24int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
25char* utf16to8(const uint16_t* utf16, size_t length);
26uint32_t utf8Char(const char** unicode, size_t* length);
27uint32_t utf16Char(const uint16_t** unicode, size_t* length);
28
29int hexDigit(char digit);
30const char* hex32(const char* line, uint32_t* out);
31const char* hex24(const char* line, uint32_t* out);
32const char* hex16(const char* line, uint16_t* out);
33const char* hex12(const char* line, uint16_t* out);
34const char* hex8(const char* line, uint8_t* out);
35const char* hex4(const char* line, uint8_t* out);
36
37void rtrim(char* string);
38
39#endif