Removed comment header, minor cleanup

This commit is contained in:
Bob Polis 2023-04-20 11:30:38 +02:00
parent ddf88a4e03
commit c7b409bae1

View File

@ -1,11 +1,3 @@
/*
* string_utils.cpp
*
* Created by Bob Polis on 14-11-2014.
* Copyright 2014 Thalictrum. All rights reserved.
*
*/
#include "string_utils.hpp" #include "string_utils.hpp"
#include <libscerror.hpp> #include <libscerror.hpp>
#include <sys/stat.h> #include <sys/stat.h>
@ -14,6 +6,8 @@
#include <cerrno> #include <cerrno>
#include <fstream> #include <fstream>
#include <algorithm> #include <algorithm>
#include <locale>
using namespace std; using namespace std;
vector<string> sc::split(const string& str, const string& sep) vector<string> sc::split(const string& str, const string& sep)
@ -158,8 +152,7 @@ void sc::create_dir(const string &path, int mode)
string sc::dirname(const string& path) { string sc::dirname(const string& path) {
string result {path}; string result {path};
vector<char> buf; vector<char> buf(PATH_MAX);
buf.resize(PATH_MAX);
if (::realpath(path.c_str(), buf.data())) { if (::realpath(path.c_str(), buf.data())) {
result = buf.data(); result = buf.data();
} }
@ -225,18 +218,18 @@ string sc::truncate(const string& str, unsigned int maxlen, int /*how*/) {
} }
string sc::lowercase(const string& str, const locale& loc) { string sc::lowercase(const string& str, const locale& loc) {
string result; string result {str};
for (const char c : str) { transform(result.cbegin(), result.cend(),
result += tolower(c, loc); result.begin(),
} [&loc](char c) { return tolower(c, loc); });
return result; return result;
} }
string sc::uppercase(const string& str, const locale& loc) { string sc::uppercase(const string& str, const locale& loc) {
string result; string result {str};
for (const char c : str) { transform(result.cbegin(), result.cend(),
result += toupper(c, loc); result.begin(),
} [&loc](char c) { return toupper(c, loc); });
return result; return result;
} }
@ -264,8 +257,7 @@ bool sc::is_valid_utf8(const string& str) {
} }
string sc::real_path(const string& path) { string sc::real_path(const string& path) {
vector<char> buf; vector<char> buf(PATH_MAX);
buf.resize(PATH_MAX);
if (::realpath(path.c_str(), buf.data())) { if (::realpath(path.c_str(), buf.data())) {
return string(buf.data()); return string(buf.data());
} }
@ -273,8 +265,7 @@ string sc::real_path(const string& path) {
} }
string sc::remove_accents(const string& text) { string sc::remove_accents(const string& text) {
vector<char> buf; vector<char> buf(text.size() * 2);
buf.resize(text.size() * 2);
size_t bufsize {buf.size()}; size_t bufsize {buf.size()};
u8_normalize(UNINORM_NFD, u8_normalize(UNINORM_NFD,
reinterpret_cast<const uint8_t*>(text.data()), reinterpret_cast<const uint8_t*>(text.data()),