X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c1d3e52e58e86c49f9d04e06ae8e0ece4b98250c..7e551bb166cb5e24d52a32938335cd18f9efb217:/String.hpp diff --git a/String.hpp b/String.hpp index a00a5e2..0bc5519 100644 --- a/String.hpp +++ b/String.hpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -22,10 +22,10 @@ #ifndef CYCRIPT_STRING_HPP #define CYCRIPT_STRING_HPP -#include "cycript.hpp" -#include "Pooling.hpp" - #include +#include + +#include "Pooling.hpp" struct CYUTF8String { const char *data; @@ -53,9 +53,18 @@ struct CYUTF8String { size_t length(strlen(data)); return length == size && memcmp(value, data, length) == 0; } + + bool operator !=(const char *value) const { + size_t length(strlen(data)); + return length != size || memcmp(value, data, length) != 0; + } + + operator std::string() const { + return std::string(data, size); + } }; -static inline std::ostream &operator <<(std::ostream &lhs, CYUTF8String &rhs) { +static inline std::ostream &operator <<(std::ostream &lhs, const CYUTF8String &rhs) { lhs.write(rhs.data, rhs.size); return lhs; } @@ -73,8 +82,23 @@ struct CYUTF16String { size_t CYGetIndex(const CYUTF8String &value); bool CYIsKey(CYUTF8String value); + bool CYGetOffset(const char *value, ssize_t &index); +bool CYStartsWith(const CYUTF8String &haystack, const CYUTF8String &needle); + +_finline const char *CYPoolCString(CYPool &pool, CYUTF8String utf8) { + return pool.strndup(utf8.data, utf8.size); +} + +_finline CYUTF8String CYPoolUTF8String(CYPool &pool, CYUTF8String utf8) { + return {pool.strndup(utf8.data, utf8.size), utf8.size}; +} + +_finline CYUTF8String CYPoolUTF8String(CYPool &pool, const std::string &value) { + return {pool.strndup(value.data(), value.size()), value.size()}; +} + CYUTF8String CYPoolUTF8String(CYPool &pool, CYUTF16String utf16); CYUTF16String CYPoolUTF16String(CYPool &pool, CYUTF8String utf8);