diff --git a/.gitignore b/.gitignore index 1bc915c..fd26a59 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,6 @@ $RECYCLE.BIN/ # Mac desktop service store files .DS_Store + +# Visual Studio OpenDB +*.VC.opendb diff --git a/Jupiter/ArrayList.h b/Jupiter/ArrayList.h index 99d1302..1716b33 100644 --- a/Jupiter/ArrayList.h +++ b/Jupiter/ArrayList.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/Jupiter/Database.cpp b/Jupiter/Database.cpp index 9b0af93..2bde975 100644 --- a/Jupiter/Database.cpp +++ b/Jupiter/Database.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015 Jessica James. + * Copyright (C) 2015-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -144,11 +144,6 @@ bool Jupiter::Database::append(const char *file, Jupiter::DataBuffer &data) return r; } -template T *get_ptr(T &in) -{ - return ∈ -} - bool Jupiter::Database::append(FILE *file, Jupiter::DataBuffer &data) { fwrite(std::addressof(data.size()), sizeof(size_t), 1, file); diff --git a/Jupiter/Functions.c b/Jupiter/Functions.c index d491631..f6c8d33 100644 --- a/Jupiter/Functions.c +++ b/Jupiter/Functions.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,622 +16,193 @@ * Written by Jessica James */ -#include // malloc #include // uintxx_t typedefs. -#include // fprintf and stderr #include // Used by getTime() -#include // toupper -#include // towupper +#include // isspace #include // pow #include "Functions.h" -// Little Endian -unsigned int getZeroByte(uint32_t *v) -{ - if ((*v & 0x000000FF) == 0) return 0; - if ((*v & 0x0000FF00) == 0) return 1; - if ((*v & 0x00FF0000) == 0) return 2; - if ((*v & 0xFF000000) == 0) return 3; - return 4; -} - -unsigned int getZeroByte2(uint64_t v) -{ - if ((v & 0x00000000000000FF) == 0) return 0; - if ((v & 0x000000000000FF00) == 0) return 1; - if ((v & 0x0000000000FF0000) == 0) return 2; - if ((v & 0x00000000FF000000) == 0) return 3; - if ((v & 0x000000FF00000000) == 0) return 4; - if ((v & 0x0000FF0000000000) == 0) return 5; - if ((v & 0x00FF000000000000) == 0) return 6; - if ((v & 0xFF00000000000000) == 0) return 7; - return 8; -} - -/* -// Big Endian -unsigned int getZeroByte(uint32_t v) -{ - if ((v & 0xFF000000) == 0) return 0; - if ((v & 0x00FF0000) == 0) return 1; - if ((v & 0x0000FF00) == 0) return 2; - if ((v & 0x000000FF) == 0) return 3; - return 4; -} - -unsigned int getZeroByte64(uint64_t v) -{ - if ((v & 0xFF00000000000000) == 0) return 0; - if ((v & 0x00FF000000000000) == 0) return 1; - if ((v & 0x0000FF0000000000) == 0) return 2; - if ((v & 0x000000FF00000000) == 0) return 3; - if ((v & 0x00000000FF000000) == 0) return 4; - if ((v & 0x0000000000FF0000) == 0) return 5; - if ((v & 0x000000000000FF00) == 0) return 6; - if ((v & 0x00000000000000FF) == 0) return 7; - return 8; -} -*/ - uint32_t getPowerTwo32(uint32_t v) { - v--; + --v; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; - v++; - return v; + return ++v; } uint64_t getPowerTwo64(uint64_t v) { - v--; + --v; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v |= v >> 32; - v++; - return v; -} - -#define STRLEN_WRAPPER(TYPE) \ - register const TYPE *s = str; \ - while (*s != 0) s++; \ - return s - str; - -size_t Jupiter_strlen(const char *str) -{ - STRLEN_WRAPPER(char) -} - -size_t Jupiter_wstrlen(const wchar_t *str) -{ - STRLEN_WRAPPER(wchar_t) -} - -size_t Jupiter_strlen8(const uint8_t *str) -{ - STRLEN_WRAPPER(uint8_t) -} - -size_t Jupiter_strlen16(const uint16_t *str) -{ - STRLEN_WRAPPER(uint16_t) -} - -size_t Jupiter_strlen32(const uint32_t *str) -{ - STRLEN_WRAPPER(uint32_t) -} - -size_t Jupiter_strlen64(const uint64_t *str) -{ - STRLEN_WRAPPER(uint64_t) -} - -size_t Jupiter_vstrlen(const void *str, size_t size) -{ - const char *s; - const char *s2; - switch (size) - { - case 0: - return 0; - case 1: - return Jupiter_strlen((const char *)str); - case 2: - return Jupiter_strlen16((const uint16_t *)str); - case 4: - return Jupiter_strlen32((const uint32_t *)str); - case 8: - return Jupiter_strlen64((const uint64_t *)str); - default: - s = (const char *)str; - s2 = s; - while ((unsigned)(s2 - s) != size) - { - s2 = s; - while ((unsigned)(s2 - s) > size) - { - if (*s2 != 0) break; - s2++; - } - s += size; - } - return (s - (const char *)str) / size; - } -} - -const char *stristr(const char *str1, const char *str2) -{ - size_t i; - size_t a; - for (i = 0; str1[i] != 0; i++) - { - if (toupper(str1[i]) == toupper(str2[0])) - { - a = 1; - while (str2[a] != 0) - { - if (toupper(str1[i + a]) != toupper(str2[a])) break; - a++; - } - if (str2[a] == 0) - { - return str1 + i; - } - } - } - return NULL; -} - -bool streql(const char *s1, const char *s2) -{ - if (s1 == s2) return true; - while (*s1 != 0 && *s1 == *s2) - { - s1++; - s2++; - } - return (*s1 == *s2); -} - -bool streqli(const char *s1, const char *s2) -{ - if (s1 == s2) return true; - while (*s1 != 0 && toupper(*s1) == toupper(*s2)) - { - s1++; - s2++; - } - if (*s1 == *s2) return true; - return false; -} - -bool wstreql(const wchar_t *s1, const wchar_t *s2) -{ - if (s1 == s2) return true; - while (*s1 != 0 && *s1 == *s2) - { - s1++; - s2++; - } - return (*s1 == *s2); + return ++v; } -bool wstreqli(const wchar_t *s1, const wchar_t *s2) +bool containsSymbol(const char *str, char c) { - if (s1 == s2) return true; - while (*s1 != 0 && towupper(*s1) == towupper(*s2)) + while (*str != 0) { - s1++; - s2++; + if (*str == c) + return true; + ++str; } - if (*s1 == *s2) return true; return false; } -bool strmatch(const char *f, const char *s) +char *getTime() { - while (*f != 0) - { - if (*f == '*') - { - f++; - while (*f == '?') - { - if (*s == 0) return false; - f++; - s++; - } - if (*f == 0) return true; - if (*f == '*') continue; - while (*f != *s) - { - if (*s == 0) return false; - s++; - } - } - else if (*f != '?' && *f != *s) return false; - f++; - s++; - } - return *s == 0; + return getTimeFormat("%a %b %d %H:%M:%S %Y %Z"); } -bool strmatchi(const char *f, const char *s) +char *getTimeFormat(const char *format) { - int fUpper; - while (*f != 0) - { - if (*f == '*') - { - f++; - while (*f == '?') - { - if (*s == 0) return false; - f++; - s++; - } - if (*f == 0) return true; - if (*f == '*') continue; - fUpper = toupper(*f); - while (fUpper != toupper(*s)) - { - if (*s == 0) return false; - s++; - } - } - else if (*f != '?' && toupper(*f) != toupper(*s)) return false; - f++; - s++; - } - return *s == 0; + time_t rawtime = time(0); + static char rtime[256]; + strftime(rtime, sizeof(rtime), format, localtime(&rawtime)); + return rtime; } -bool wstrmatch(const wchar_t *f, const wchar_t *s) -{ - while (*f != 0) - { - if (*f == L'*') - { - f++; - while (*f == L'?') - { - if (*s == 0) return false; - f++; - s++; - } - if (*f == 0) return true; - if (*f == L'*') continue; - while (*f != *s) - { - if (*s == 0) return false; - s++; - } - } - else if (*f != L'?' && *f != *s) return false; - f++; - s++; - } - return *s == 0; -} +/** Character to integer conversion table */ -bool wstrmatchi(const wchar_t *f, const wchar_t *s) +const unsigned char base_table[] = { - wint_t fUpper; - while (*f != 0) - { - if (*f == L'*') - { - f++; - while (*f == L'?') - { - if (*s == 0) return false; - f++; - s++; - } - if (*f == 0) return true; - if (*f == L'*') continue; - fUpper = towupper(*f); - while (fUpper != towupper(*s)) - { - if (*s == 0) return false; - s++; - } - } - else if (*f != L'?' && towupper(*f) != towupper(*s)) return false; - f++; - s++; - } - return *s == 0; -} + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 127, 127, 127, 127, 127, 127, + 127, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 127, 127, 127, 127, 127, + 127, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 127, 127, 127, 127, 127, -char *charToChar(const char *a, int b, int c) -{ - char *r = (char *) malloc(sizeof(char) * (c-b+1)); - if (r != NULL) - { - int i = 0; - while (b < c) - { - r[i] = a[b]; - i++; - b++; - } - r[i] = 0; - } - else fprintf(stderr, "ERROR: UNABLE TO ALLOCATE IN %s" ENDL, __FUNCTION__); - return r; -} + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 +}; -wchar_t *wcharToChar(const wchar_t *a, int b, int c) +const signed char hexadecimal_table[] = { - wchar_t *r = (wchar_t *)malloc(sizeof(wchar_t)* (c - b + 1)); - if (r != NULL) - { - int i = 0; - while (b < c) - { - r[i] = a[b]; - i++; - b++; - } - r[i] = 0; - } - else fprintf(stderr, "ERROR: UNABLE TO ALLOCATE IN %s" ENDL, __FUNCTION__); - return r; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -void trim(char *str) -{ - int p = 0; - int x = 0; - int i; - while (str[p] != 0) - { - if (str[p] == 10) - { - str[p] = 0; - } - else if (str[p] == 13) - { - str[p] = 0; - } - p++; - } - for (i = 0; i < p; i++) - { - if (str[i] != 0) - { - str[x] = str[i]; - x++; - } - } - str[x] = 0; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; -char *getWord(const char *str, int w) +const signed char decimal_table[] = { - char *result; - int x = 0; - int y; - int i; - for (i = 0; i < w; x++) - { - if (str[x] == 0) return NULL; - if (str[x] == ' ') i++; - } - for (y = x; str[y] != ' ' && str[y] != 0; y++); - result = (char *) malloc(sizeof(char) * (y-x+1)); - if (result != NULL) - { - for (i = 0; x < y; i++) - { - result[i] = str[x]; - x++; - } - result[i] = 0; - } - else fprintf(stderr, "ERROR: UNABLE TO ALLOCATE IN %s" ENDL, __FUNCTION__); - return result; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -unsigned int countSymbol(const char *str, char c) -{ - unsigned int result = 0; - while(*str != 0) - { - if (*str == c) result++; - str++; - } - return result; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; -unsigned int wordCount(const char *str) +const signed char octal_table[] = { - unsigned int result = 0; - int i; - for (i = 0; str[i] != 0; i++) - { - if (str[i] == ' ') - { - if (i > 0) - { - if (str[i-1] > ' ') result++; - } - } - else if (str[i+1] < ' ') result++; - } - return result; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -unsigned int countLines(const char *str) -{ - unsigned int r = 0; - while (*str != 0) - { - if ((*str == '\r' && *(str + 1) != '\n') || *str == '\n') r++; - str++; - } - return r; -} - -char *getLine(const char *str, unsigned int l) -{ - char *result; - unsigned int x = 0; - unsigned int y; - unsigned int i; - for (i = 0; i < l; x++) - { - if (str[x] == 0) break; - if (str[x] == '\n' || (str[x] == '\r' && str[x+1] != '\n')) i++; - } - for (y = x; str[y] != '\r' && str[y] != '\n' && str[y] != 0; y++);// if (str[y] == 0) break; - result = (char *) malloc(sizeof(char) * (y-x+1)); - if (result != NULL) - { - for (i = 0; x < y; i++) - { - result[i] = str[x]; - x++; - } - result[i] = 0; - } - else fprintf(stderr, "ERROR: UNABLE TO ALLOCATE IN %s" ENDL, __FUNCTION__); - return result; -} + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; -int findSymbol(const char *str, char c, int pos) -{ - int r = 0; - int a = 0; - while (str[r] != 0) - { - if (str[r] == c) - { - if (a == pos) return r; - a++; - } - r++; - } - return -1; -} +/** Single character functions */ -bool containsSymbol(const char *str, char c) +bool Jupiter_isBase(unsigned char chr, int base) { - int i; - for (i = 0; str[i] != 0; i++) if (str[i] == c) return true; - return false; + return base_table[chr] < base; } -char *makestr(const char *str) +bool Jupiter_isHex(unsigned char chr) { - char *r; - size_t len; - if (str == NULL) return NULL; - len = Jupiter_strlen(str); - r = (char *) malloc(sizeof(char) * (len + 1)); - if (r != NULL) - { - r[len] = 0; - while (len != 0) - { - len--; - r[len] = str[len]; - } - return r; - } - return NULL; + return hexadecimal_table[chr] != -1; } -char *getTime() +bool Jupiter_isDecimal(unsigned char chr) { - return getTimeFormat("%a %b %d %H:%M:%S %Y %Z"); + return decimal_table[chr] != -1; } -char *getTimeFormat(const char *format) +bool Jupiter_isOctal(unsigned char chr) { - time_t rawtime = time(0); - static char rtime[256]; - strftime(rtime, sizeof(rtime), format, localtime(&rawtime)); - return rtime; + return octal_table[chr] != -1; } -/** Character to integer conversion table */ - -const unsigned char baseTable[] = +int Jupiter_getBase(unsigned char chr, int base) { - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 127, 127, 127, 127, 127, 127, - 127, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 127, 127, 127, 127, 127, - 127, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 127, 127, 127, 127, 127, - - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, -}; - -/** Single character functions */ - -bool Jupiter_isBase(unsigned char c, int base) -{ - return baseTable[c] < base; + chr = base_table[chr]; + if (chr < base) + return chr; + return -1; } -bool Jupiter_isHex(unsigned char c) +int Jupiter_getHex(unsigned char chr) { - return Jupiter_isBase(c, 16); + return hexadecimal_table[chr]; } -bool Jupiter_isDecimal(unsigned char c) +int Jupiter_getDecimal(unsigned char chr) { - return Jupiter_isBase(c, 10); + return decimal_table[chr]; } -int Jupiter_getBase(unsigned char c, int base) +int Jupiter_getOctal(unsigned char chr) { - c = baseTable[c]; - if (c < base) return c; - return -1; + return octal_table[chr]; } /** Unsafe string converters */ int Jupiter_strtoi(const char *str, int base) { - while (isspace(*str)) str++; + while (isspace(*str)) + ++str; return Jupiter_strtoi_nospace(str, base); } long long Jupiter_strtoll(const char *str, int base) { - while (isspace(*str)) str++; + while (isspace(*str)) + ++str; return Jupiter_strtoll_nospace(str, base); } unsigned int Jupiter_strtoui(const char *str, int base) { - while (isspace(*str)) str++; + while (isspace(*str)) + ++str; return Jupiter_strtoui_nospace(str, base); } unsigned long long Jupiter_strtoull(const char *str, int base) { - while (isspace(*str)) str++; + while (isspace(*str)) + ++str; return Jupiter_strtoull_nospace(str, base); } double Jupiter_strtod(const char *str) { - while (isspace(*str)) str++; + while (isspace(*str)) + ++str; return Jupiter_strtod_nospace(str); } @@ -651,25 +222,27 @@ unsigned int Jupiter_strtoui_nospace(const char *str, int base) { unsigned int total = 0; int tval; - if (*str == '-') return Jupiter_strtoi_nospace(str, base); - if (*str == '+') str++; + if (*str == '-') + return Jupiter_strtoi_nospace(str, base); + + if (*str == '+') + ++str; if (base == 0) // Guess a base. { if (*str == '0') { - str++; - switch (*str) + switch (*++str) { case 'X': case 'x': - str++; + ++str; base = 16; break; case 'B': case 'b': - str++; + ++str; base = 2; break; default: @@ -683,15 +256,16 @@ unsigned int Jupiter_strtoui_nospace(const char *str, int base) { if (*str == '0') { - str++; - if (*str == 'x' || *str == 'X') str++; + ++str; + if (*str == 'x' || *str == 'X') + ++str; } } while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - str++; + ++str; } return total; @@ -701,25 +275,27 @@ unsigned long long Jupiter_strtoull_nospace(const char *str, int base) { unsigned long long total = 0; int tval; - if (*str == '-') return Jupiter_strtoi_nospace(str, base); - if (*str == '+') str++; + if (*str == '-') + return Jupiter_strtoi_nospace(str, base); + + if (*str == '+') + ++str; if (base == 0) // Guess a base. { if (*str == '0') { - str++; - switch (*str) + switch (*++str) { case 'X': case 'x': - str++; + ++str; base = 16; break; case 'B': case 'b': - str++; + ++str; base = 2; break; default: @@ -733,15 +309,16 @@ unsigned long long Jupiter_strtoull_nospace(const char *str, int base) { if (*str == '0') { - str++; - if (*str == 'x' || *str == 'X') str++; + ++str; + if (*str == 'x' || *str == 'X') + ++str; } } while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - str++; + ++str; } return total; @@ -754,23 +331,26 @@ double Jupiter_strtod_nospace(const char *str) double decimal = 0.0; int tval; - if (*str == '-') return -1 * Jupiter_strtod_nospace(++str); - if (*str == '+') str++; + if (*str == '-') + return -1 * Jupiter_strtod_nospace(++str); + + if (*str == '+') + ++str; while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - str++; + ++str; } if (*str == '.') { - str++; + ++str; tval = base; while ((decimal = Jupiter_getBase(*str, base)) != -1) { total = total + (decimal / tval); - str++; + ++str; tval = tval * base; } if (*str == 'e' || *str == 'E') @@ -785,57 +365,51 @@ double Jupiter_strtod_nospace(const char *str) int Jupiter_strtoi_s(const char *str, size_t length, int base) { while (length != 0 && isspace(*str)) - { - str++; - length--; - } + ++str, --length; + return Jupiter_strtoi_nospace_s(str, length, base); } long long Jupiter_strtoll_s(const char *str, size_t length, int base) { while (length != 0 && isspace(*str)) - { - str++; - length--; - } + ++str, --length; + return Jupiter_strtoll_nospace_s(str, length, base); } unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base) { while (length != 0 && isspace(*str)) - { - str++; - length--; - } + ++str, --length; + return Jupiter_strtoui_nospace_s(str, length, base); } unsigned long long Jupiter_strtoull_s(const char *str, size_t length, int base) { while (length != 0 && isspace(*str)) - { - str++; - length--; - } + ++str, --length; + return Jupiter_strtoull_nospace_s(str, length, base); } double Jupiter_strtod_s(const char *str, size_t length) { while (length != 0 && isspace(*str)) - { - str++; - length--; - } + ++str, --length; + return Jupiter_strtod_nospace_s(str, length); } int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base) { - if (length == 0) return 0; - if (*str != '-') return Jupiter_strtoui_nospace_s(str, length, base); + if (length == 0) + return 0; + + if (*str != '-') + return Jupiter_strtoui_nospace_s(str, length, base); + return -1 * Jupiter_strtoui_nospace_s(++str, --length, base); } @@ -843,35 +417,48 @@ unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base) { unsigned int total = 0; int tval; - if (length == 0) return total; - if (*str == '-') return Jupiter_strtoi_nospace(str, base); + + if (length == 0) + return total; + + if (*str == '-') + return Jupiter_strtoi_nospace(str, base); if (*str == '+') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } if (base == 0) // Guess a base. { if (*str == '0') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; switch (*str) { case 'X': case 'x': - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; base = 16; break; + case 'B': case 'b': - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; base = 2; break; + default: base = 8; break; @@ -883,12 +470,14 @@ unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base) { if (*str == '0') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; if (*str == 'x' || *str == 'X') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } } } @@ -896,8 +485,9 @@ unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base) while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } return total; @@ -914,33 +504,44 @@ unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, in { unsigned long long total = 0; int tval; - if (length == 0) return total; - if (*str == '-') return Jupiter_strtoi_nospace(str, base); + + if (length == 0) + return total; + + if (*str == '-') + return Jupiter_strtoi_nospace(str, base); if (*str == '+') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } if (base == 0) // Guess a base. { if (*str == '0') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; switch (*str) { case 'X': case 'x': - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; base = 16; break; case 'B': case 'b': - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; base = 2; break; default: @@ -954,12 +555,16 @@ unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, in { if (*str == '0') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; if (*str == 'x' || *str == 'X') { - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + + ++str; } } } @@ -967,8 +572,9 @@ unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, in while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } return total; @@ -981,31 +587,35 @@ double Jupiter_strtod_nospace_s(const char *str, size_t length) double decimal = 0.0; int tval; - if (length == 0) return 0; - if (*str == '-') return -1 * Jupiter_strtod_nospace_s(++str, --length); + if (length == 0) + return 0; + + if (*str == '-') + return -1 * Jupiter_strtod_nospace_s(++str, --length); + if (*str == '+') - { - str++; - length--; - } + ++str, --length; while ((tval = Jupiter_getBase(*str, base)) != -1) { total = base * total + tval; - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; } if (*str == '.') { - str++; - length--; + ++str; + --length; + tval = base; while (length != 0 && (decimal = Jupiter_getBase(*str, base)) != -1) { total = total + (decimal / tval); - if (--length == 0) return total; - str++; + if (--length == 0) + return total; + ++str; tval = tval * base; } if (*str == 'e' || *str == 'E') @@ -1030,17 +640,17 @@ const uint32_t bitmask_table[] = 0xFFFFFFFFU }; -const unsigned char *netmask_table[] = -{ - "\x00\x00\x00\x00", "\x80\x00\x00\x00", "\xC0\x00\x00\x00", "\xE0\x00\x00\x00", - "\xF0\x00\x00\x00", "\xF8\x00\x00\x00", "\xFC\x00\x00\x00", "\xFE\x00\x00\x00", - "\xFF\x00\x00\x00", "\xFF\x80\x00\x00", "\xFF\xC0\x00\x00", "\xFF\xE0\x00\x00", - "\xFF\xF0\x00\x00", "\xFF\xF8\x00\x00", "\xFF\xFC\x00\x00", "\xFF\xFE\x00\x00", - "\xFF\xFF\x00\x00", "\xFF\xFF\x80\x00", "\xFF\xFF\xC0\x00", "\xFF\xFF\xE0\x00", - "\xFF\xFF\xF0\x00", "\xFF\xFF\xF8\x00", "\xFF\xFF\xFC\x00", "\xFF\xFF\xFE\x00", - "\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\x80", "\xFF\xFF\xFF\xC0", "\xFF\xFF\xFF\xE0", - "\xFF\xFF\xFF\xF0", "\xFF\xFF\xFF\xF8", "\xFF\xFF\xFF\xFC", "\xFF\xFF\xFF\xFE", - "\xFF\xFF\xFF\xFF" +const uint8_t netmask_table[][4] = +{ + { 0x00, 0x00, 0x00, 0x00 }, { 0x80, 0x00, 0x00, 0x00 }, { 0xC0, 0x00, 0x00, 0x00 }, { 0xE0, 0x00, 0x00, 0x00 }, + { 0xF0, 0x00, 0x00, 0x00 }, { 0xF8, 0x00, 0x00, 0x00 }, { 0xFC, 0x00, 0x00, 0x00 }, { 0xFE, 0x00, 0x00, 0x00 }, + { 0xFF, 0x00, 0x00, 0x00 }, { 0xFF, 0x80, 0x00, 0x00 }, { 0xFF, 0xC0, 0x00, 0x00 }, { 0xFF, 0xE0, 0x00, 0x00 }, + { 0xFF, 0xF0, 0x00, 0x00 }, { 0xFF, 0xF8, 0x00, 0x00 }, { 0xFF, 0xFC, 0x00, 0x00 }, { 0xFF, 0xFE, 0x00, 0x00 }, + { 0xFF, 0xFF, 0x00, 0x00 }, { 0xFF, 0xFF, 0x80, 0x00 }, { 0xFF, 0xFF, 0xC0, 0x00 }, { 0xFF, 0xFF, 0xE0, 0x00 }, + { 0xFF, 0xFF, 0xF0, 0x00 }, { 0xFF, 0xFF, 0xF8, 0x00 }, { 0xFF, 0xFF, 0xFC, 0x00 }, { 0xFF, 0xFF, 0xFE, 0x00 }, + { 0xFF, 0xFF, 0xFF, 0x00 }, { 0xFF, 0xFF, 0xFF, 0x80 }, { 0xFF, 0xFF, 0xFF, 0xC0 }, { 0xFF, 0xFF, 0xFF, 0xE0 }, + { 0xFF, 0xFF, 0xFF, 0xF0 }, { 0xFF, 0xFF, 0xFF, 0xF8 }, { 0xFF, 0xFF, 0xFF, 0xFC }, { 0xFF, 0xFF, 0xFF, 0xFE }, + { 0xFF, 0xFF, 0xFF, 0xFF } }; uint32_t Jupiter_prefix_length_to_bitmask(uint8_t prefix_length) diff --git a/Jupiter/Functions.h b/Jupiter/Functions.h index dd3bb5e..d19afa0 100644 --- a/Jupiter/Functions.h +++ b/Jupiter/Functions.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -74,7 +74,7 @@ namespace Jupiter * @return Pointer to the first instance of a character in str2 being in str1, or nullptr if there is none. */ template inline const T *strpbrk(const T *str1, const T *str2); - template inline const T *strpbrk(const T *str1, const T str2); + template inline const T *strpbrk(const T *str, const T element); /** * @brief Checks if two strings are equal. @@ -94,183 +94,6 @@ extern "C" #include #endif // __cplusplus -/** -* @brief Case insensitive version of strstr(). -* -* @param str1 String to be scanned. -* @param str2 String to be matched. -* @return Pointer to the first occurance of str2 in str1 if it exists, NULL otherwise. -*/ -JUPITER_API const char *stristr(const char *str1, const char *str2); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_strlen(const char *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_wstrlen(const wchar_t *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_strlen8(const uint8_t *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_strlen16(const uint16_t *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_strlen32(const uint32_t *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_strlen64(const uint64_t *str); - -/** -* @brief Returns the length of a C-style string. -* -* @param str C-style string to get the length of. -* @return Length of the C-style string. -*/ -JUPITER_API size_t Jupiter_vstrlen(const void *str, size_t size); - -/** -* @brief Checks if two strings are equal. This function is case-sensitive. -* -* @param str1 String to be compared. -* @param str2 String to be compared. -* @return True if the strings are equal, false otherwise. -*/ -JUPITER_API bool streql(const char *str1, const char *str2); -JUPITER_API bool wstreql(const wchar_t *str1, const wchar_t *str2); - -/** -* @brief Checks if two strings are equal. This function is not case-sensitive. -* -* @param str1 String to be compared. -* @param str2 String to be compared. -* @return True if the strings are equal, false otherwise. -*/ -JUPITER_API bool streqli(const char *str1, const char *str2); -JUPITER_API bool wstreqli(const wchar_t *str1, const wchar_t *str2); - -/** -* @brief Checks if a string matches a wildcard format. -* Note: Case sensitive. -* -* @param format Sring containing the wildcard format information. -* @param str2 String to be compared. -* @return True if the string matches the wildcard format, false otherwise. -*/ -JUPITER_API bool strmatch(const char *format, const char *str); -JUPITER_API bool wstrmatch(const wchar_t *format, const wchar_t *str); - -/** -* @brief Checks if a string matches a wildcard format. -* Note: Case insensitive. -* -* @param format Sring containing the wildcard format information. -* @param str2 String to be compared. -* @return True if the string matches the wildcard format, false otherwise. -*/ -JUPITER_API bool strmatchi(const char *format, const char *str); -JUPITER_API bool wstrmatchi(const wchar_t *format, const wchar_t *str); - -/** -* @brief Returns a copy of a substring. -* -* @param str String -* @param a String to be compared. -* @param b String to be compared. -* @return String containing the substring, or NULL on malloc failure. -*/ -JUPITER_API char *charToChar(const char *str, int a, int b); -JUPITER_API wchar_t *wcharToChar(const wchar_t *str, int a, int b); - -/** -* @brief Removes any carriage-returns (\r) and new lines (\n) from a string. -* -* @param str String to be trimed. -*/ -JUPITER_API void trim(char *str); - -/** -* @brief Returns a copy of a "word" from a string. -* -* @param str String to be parsed. -* @param w Position of the word, starting at 0. -* @return String containing the word on success, or NULL otherwise. -*/ -JUPITER_API char *getWord(const char *str, int w); - -/** -* @brief Returns the number of occurances of a given character. -* -* @param str String to be scanned. -* @param c Character to be counted. -* @return Total number of occurances of a character in a string. -*/ -JUPITER_API unsigned int countSymbol(const char *str, char c); - -/** -* @brief Returns the number of space-deliminated words in a string. -* -* @param str String to be scanned. -* @return Total number of space-deliminated words in a string. -*/ -JUPITER_API unsigned int wordCount(const char *str); - -/** -* @brief Returns the number of newlines in a string. -* -* @param str String to be scanned. -* @return Total number of newlines in a string. -*/ -JUPITER_API unsigned int countLines(const char *str); - -/** -* @brief Returns a substring in the form of a new String, -* -* @param str String to be scanned. -* @return String representing a single line of the input string on success, NULL otherwise. -*/ -JUPITER_API char *getLine(const char *str, unsigned int l); - -/** -* @brief Returns the position of the n'th occurance of a character in a string. -* -* @param str String to be scanned. -* @param c Character to find. -* @param n Position of the character to search for. -* @return Position of the n'th occurance of a character if it exists, -1 otherwise. -*/ -JUPITER_API int findSymbol(const char *str, char c, int n); - /** * @brief Checks if a character exists in a string. * @@ -279,14 +102,6 @@ JUPITER_API int findSymbol(const char *str, char c, int n); */ JUPITER_API bool containsSymbol(const char *str, char c); -/** -* @brief Creates a copy of a string. -* -* @param str String to copy. -* @return String containing a copy of the input string on success, NULL otherwise. -*/ -JUPITER_API char *makestr(const char *str); - /** * @brief Returns the current time in a string format. * This will vary depending on locale. @@ -332,7 +147,7 @@ JUPITER_API uint64_t getPowerTwo64(uint64_t number); * @param c Character to check. * @return True if the character is a hexadecimal digit, false otherwise. */ -JUPITER_API bool Jupiter_isBase(unsigned char c, int base); +JUPITER_API bool Jupiter_isBase(unsigned char chr, int base); /** * @brief Checks if a character is a hexadecimal digit character. (base 16) @@ -340,7 +155,7 @@ JUPITER_API bool Jupiter_isBase(unsigned char c, int base); * @param c Character to check. * @return True if the character is a hexadecimal digit, false otherwise. */ -JUPITER_API bool Jupiter_isHex(unsigned char c); +JUPITER_API bool Jupiter_isHex(unsigned char chr); /** * @brief Checks if a character is a decimal digit character. (base 10) @@ -348,7 +163,15 @@ JUPITER_API bool Jupiter_isHex(unsigned char c); * @param c Character to check. * @return True if the character is a decimal digit, false otherwise. */ -JUPITER_API bool Jupiter_isDecimal(unsigned char c); +JUPITER_API bool Jupiter_isDecimal(unsigned char chr); + +/** +* @brief Checks if a character is an octal digit character. (base 10) +* +* @param c Character to check. +* @return True if the character is a octal digit, false otherwise. +*/ +JUPITER_API bool Jupiter_isOctal(unsigned char chr); /** * @brief Fetches a character's represented integral value. @@ -358,7 +181,31 @@ JUPITER_API bool Jupiter_isDecimal(unsigned char c); * @param base Base of the representation. * @return A character's represented integral value on success, -1 otherwise. */ -JUPITER_API int Jupiter_getBase(unsigned char c, int base); +JUPITER_API int Jupiter_getBase(unsigned char chr, int base); + +/** +* @brief Fetches a hexadecimal character's represented integral value. (base 16) +* +* @param c Character to fetch value of. +* @return A character's represented integral value on success, -1 otherwise. +*/ +JUPITER_API int Jupiter_getHex(unsigned char chr); + +/** +* @brief Fetches a decimal character's represented integral value. (base 10) +* +* @param c Character to fetch value of. +* @return A character's represented integral value on success, -1 otherwise. +*/ +JUPITER_API int Jupiter_getDecimal(unsigned char chr); + +/** +* @brief Fetches a octal character's represented integral value. (base 8) +* +* @param c Character to fetch value of. +* @return A character's represented integral value on success, -1 otherwise. +*/ +JUPITER_API int Jupiter_getOctal(unsigned char chr); /** * @brief Interprets a string into an integer. @@ -474,20 +321,20 @@ JUPITER_API uint32_t Jupiter_prefix_length_to_netmask(uint8_t prefix_length); /** strlen implementation */ template inline size_t Jupiter::strlen(const T *str) { - register const T *s = str; - while (*s != 0) s++; + const T *s = str; + while (*s != 0) + ++s; return s - str; } /** strcpy implementation */ template inline T *Jupiter::strcpy(T *dest, const T *source) { - register T *d = dest; + T *d = dest; while (*source != 0) { *d = *source; - d++; - source++; + ++d, ++source; } *d = *source; return dest; @@ -499,7 +346,7 @@ template inline T *Jupiter::strcpy(T *dest, const T *source, size_t dest[length] = 0; while (length > 0) { - length--; + --length; dest[length] = source[length]; } return dest; @@ -513,32 +360,32 @@ template inline const T *Jupiter::strpbrk(const T *str1, const T *st s = str2; while (*s != 0) { - if (*str1 == *s) return str1; - s++; + if (*str1 == *s) + return str1; + ++s; } - str1++; + ++str1; } return nullptr; } -template inline const T *Jupiter::strpbrk(const T *str1, const T e) +template inline const T *Jupiter::strpbrk(const T *str, const T element) { - while (*str1 != 0) + while (*str != 0) { - if (*str1 == e) return str1; - str1++; + if (*str == element) + return str; + ++str; } return nullptr; } template inline bool Jupiter::streql(const T *str1, const T *str2) { - if (str1 == str2) return true; + if (str1 == str2) + return true; while (*str1 != 0 && *str1 == *str2) - { - str1++; - str2++; - } + ++str1, ++str2; return (*str1 == *str2); } diff --git a/Jupiter/IRC_Client.cpp b/Jupiter/IRC_Client.cpp index bbec229..dc4e6d4 100644 --- a/Jupiter/IRC_Client.cpp +++ b/Jupiter/IRC_Client.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2015 Jessica James. + * Copyright (C) 2013-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/Jupiter/String_Type_Imp.h b/Jupiter/String_Type_Imp.h index 89da0c2..67043b2 100644 --- a/Jupiter/String_Type_Imp.h +++ b/Jupiter/String_Type_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2015 Jessica James. + * Copyright (C) 2014-2016 Jessica James. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -187,24 +187,24 @@ template<> inline void Jupiter::String_Type::processEscapeSequences() case '1': case '2': case '3': - if (index + 1 != Jupiter::String_Type::length && Jupiter_isBase(this->get(index + 1), 8)) + if (index + 1 != Jupiter::String_Type::length && Jupiter_isOctal(this->get(index + 1))) { - if (index + 2 != Jupiter::String_Type::length && Jupiter_isBase(this->get(index + 2), 8)) - this->replace(index - 1, 4, static_cast(Jupiter_getBase(this->get(index), 8)) << 6 | static_cast(Jupiter_getBase(this->get(index + 1), 8)) << 3 | static_cast(Jupiter_getBase(this->get(index + 2), 8))); + if (index + 2 != Jupiter::String_Type::length && Jupiter_isOctal(this->get(index + 2))) + this->replace(index - 1, 4, static_cast(Jupiter_getOctal(this->get(index))) << 6 | static_cast(Jupiter_getOctal(this->get(index + 1))) << 3 | static_cast(Jupiter_getOctal(this->get(index + 2)))); else - this->replace(index - 1, 3, static_cast(Jupiter_getBase(this->get(index), 8)) << 3 | static_cast(Jupiter_getBase(this->get(index + 1), 8))); + this->replace(index - 1, 3, static_cast(Jupiter_getOctal(this->get(index))) << 3 | static_cast(Jupiter_getOctal(this->get(index + 1)))); } else - this->replace(index - 1, 2, static_cast(Jupiter_getBase(this->get(index), 8))); + this->replace(index - 1, 2, static_cast(Jupiter_getOctal(this->get(index)))); break; case '4': case '5': case '6': case '7': - if (index + 1 != Jupiter::String_Type::length && Jupiter_isBase(this->get(index + 1), 8)) - this->replace(index - 1, 3, static_cast(Jupiter_getBase(this->get(index), 8)) << 3 | static_cast(Jupiter_getBase(this->get(index + 1), 8))); + if (index + 1 != Jupiter::String_Type::length && Jupiter_isOctal(this->get(index + 1))) + this->replace(index - 1, 3, static_cast(Jupiter_getOctal(this->get(index))) << 3 | static_cast(Jupiter_getOctal(this->get(index + 1)))); else - this->replace(index - 1, 2, static_cast(Jupiter_getBase(this->get(index), 8))); + this->replace(index - 1, 2, static_cast(Jupiter_getOctal(this->get(index)))); break; case 'a': this->replace(index - 1, 2, '\a'); @@ -241,20 +241,20 @@ template<> inline void Jupiter::String_Type::processEscapeSequences() break; case 'x': if (Jupiter::String_Type::length >= index + 2 - && Jupiter_isBase(this->get(index + 1), 16) && Jupiter_isBase(this->get(index + 2), 16)) - this->replace(index - 1, 4, static_cast(Jupiter_getBase(this->get(index + 1), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 2), 16))); + && Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2))) + this->replace(index - 1, 4, static_cast(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast(Jupiter_getHex(this->get(index + 2)))); break; case 'U': if (Jupiter::String_Type::length >= index + 8 - && Jupiter_isBase(this->get(index + 1), 16) && Jupiter_isBase(this->get(index + 2), 16) && Jupiter_isBase(this->get(index + 3), 16) && Jupiter_isBase(this->get(index + 4), 16) && Jupiter_isBase(this->get(index + 5), 16) && Jupiter_isBase(this->get(index + 6), 16) && Jupiter_isBase(this->get(index + 7), 16) && Jupiter_isBase(this->get(index + 8), 16)) + && Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2)) && Jupiter_isHex(this->get(index + 3)) && Jupiter_isHex(this->get(index + 4)) && Jupiter_isHex(this->get(index + 5)) && Jupiter_isHex(this->get(index + 6)) && Jupiter_isHex(this->get(index + 7)) && Jupiter_isHex(this->get(index + 8))) { - uint32_t codepoint = static_cast(Jupiter_getBase(this->get(index + 1), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 2), 16)); + uint32_t codepoint = static_cast(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast(Jupiter_getHex(this->get(index + 2))); codepoint <<= 8; - codepoint |= static_cast(Jupiter_getBase(this->get(index + 3), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 4), 16)); + codepoint |= static_cast(Jupiter_getHex(this->get(index + 3))) << 4 | static_cast(Jupiter_getHex(this->get(index + 4))); codepoint <<= 8; - codepoint |= static_cast(Jupiter_getBase(this->get(index + 5), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 6), 16)); + codepoint |= static_cast(Jupiter_getHex(this->get(index + 5))) << 4 | static_cast(Jupiter_getHex(this->get(index + 6))); codepoint <<= 8; - codepoint |= static_cast(Jupiter_getBase(this->get(index + 7), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 8), 16)); + codepoint |= static_cast(Jupiter_getHex(this->get(index + 7))) << 4 | static_cast(Jupiter_getHex(this->get(index + 8))); if (codepoint <= 0x007F) this->replace(index - 1, 10, static_cast(codepoint)); else if (codepoint <= 0x07FF) @@ -288,11 +288,11 @@ template<> inline void Jupiter::String_Type::processEscapeSequences() break; case 'u': if (Jupiter::String_Type::length >= index + 4 - && Jupiter_isBase(this->get(index + 1), 16) && Jupiter_isBase(this->get(index + 2), 16) && Jupiter_isBase(this->get(index + 3), 16) && Jupiter_isBase(this->get(index + 4), 16)) + && Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2)) && Jupiter_isHex(this->get(index + 3)) && Jupiter_isHex(this->get(index + 4))) { - uint16_t codepoint = static_cast(Jupiter_getBase(this->get(index + 1), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 2), 16)); + uint16_t codepoint = static_cast(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast(Jupiter_getHex(this->get(index + 2))); codepoint <<= 8; - codepoint |= static_cast(Jupiter_getBase(this->get(index + 3), 16)) << 4 | static_cast(Jupiter_getBase(this->get(index + 4), 16)); + codepoint |= static_cast(Jupiter_getHex(this->get(index + 3))) << 4 | static_cast(Jupiter_getHex(this->get(index + 4))); if (codepoint <= 0x007F) this->replace(index - 1, 6, static_cast(codepoint)); else if (codepoint <= 0x07FF) diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 8a5873a..67f940e 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ