2019-08-15 10:45:18 +02:00
|
|
|
/***************************************************************************
|
2022-05-14 14:00:20 +02:00
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* for WiiXplorer 2010
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <cstring>
|
2022-02-04 16:25:44 +01:00
|
|
|
#include <string>
|
2022-05-14 14:00:20 +02:00
|
|
|
#include <strings.h>
|
2020-04-29 18:02:36 +02:00
|
|
|
#include <utils/StringTools.h>
|
2022-02-04 16:25:44 +01:00
|
|
|
#include <wut_types.h>
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2022-09-19 21:47:09 +02:00
|
|
|
std::string StringTools::truncate(const std::string &str, size_t width, bool show_ellipsis) {
|
|
|
|
if (str.length() > width - 3) {
|
|
|
|
if (show_ellipsis) {
|
|
|
|
return str.substr(0, width - 3) + "...";
|
|
|
|
} else {
|
|
|
|
return str.substr(0, width - 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) {
|
|
|
|
if (!string || !compare)
|
2019-08-15 10:45:18 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
char TokCopy[512];
|
|
|
|
strncpy(TokCopy, compare, sizeof(TokCopy));
|
|
|
|
TokCopy[511] = '\0';
|
|
|
|
|
2020-05-03 12:30:15 +02:00
|
|
|
char *strTok = strtok(TokCopy, separator);
|
2019-08-15 10:45:18 +02:00
|
|
|
|
2021-09-25 14:26:18 +02:00
|
|
|
while (strTok != nullptr) {
|
2019-08-15 10:45:18 +02:00
|
|
|
if (strcasecmp(string, strTok) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-09-25 14:26:18 +02:00
|
|
|
strTok = strtok(nullptr, separator);
|
2019-08-15 10:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|