Squashed 'deps/ox/' content from commit c63e0c1
git-subtree-dir: deps/ox git-subtree-split: c63e0c1d72f30cfb7b3076c69744b0f53d4d79b1
This commit is contained in:
91
src/ox/std/strops.cpp
Normal file
91
src/ox/std/strops.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2015 - 2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "strops.hpp"
|
||||
|
||||
int ox_strcmp(const char *str1, const char *str2) {
|
||||
auto retval = 0;
|
||||
auto i = 0;
|
||||
while (str1[i] || str2[i]) {
|
||||
if (str1[i] < str2[i]) {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if (str1[i] > str2[i]) {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ox_strlen(const char *str1) {
|
||||
int len;
|
||||
for (len = 0; str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
int ox_strlen(char *str1) {
|
||||
int len;
|
||||
for (len = 0; str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
const char *ox_strchr(const char *str, int character, size_t maxLen) {
|
||||
for (size_t i = 0; i <= maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char *ox_strchr(char *str, int character, size_t maxLen) {
|
||||
for (size_t i = 0; i < maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ox_lastIndexOf(const char *str, int character, int maxLen) {
|
||||
int retval = -1;
|
||||
for (int i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
retval = i;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ox_lastIndexOf(char *str, int character, int maxLen) {
|
||||
int retval = -1;
|
||||
for (int i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
retval = i;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ox_atoi(const char *str) {
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
|
||||
for (auto i = ox_strlen(str) - 1; i != -1; i--) {
|
||||
total += (str[i] - '0') * multiplier;
|
||||
multiplier *= 10;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
Reference in New Issue
Block a user