From c7b409bae1b40832e2095099a265b3c9c231c385 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 20 Apr 2023 11:30:38 +0200 Subject: [PATCH] Removed comment header, minor cleanup --- src/string_utils.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/string_utils.cpp b/src/string_utils.cpp index 1de289d..78cfc3c 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -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 #include @@ -14,6 +6,8 @@ #include #include #include +#include + using namespace std; vector 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 result {path}; - vector buf; - buf.resize(PATH_MAX); + vector buf(PATH_MAX); if (::realpath(path.c_str(), 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 result; - for (const char c : str) { - result += tolower(c, loc); - } + string result {str}; + transform(result.cbegin(), result.cend(), + result.begin(), + [&loc](char c) { return tolower(c, loc); }); return result; } string sc::uppercase(const string& str, const locale& loc) { - string result; - for (const char c : str) { - result += toupper(c, loc); - } + string result {str}; + transform(result.cbegin(), result.cend(), + result.begin(), + [&loc](char c) { return toupper(c, loc); }); return result; } @@ -264,8 +257,7 @@ bool sc::is_valid_utf8(const string& str) { } string sc::real_path(const string& path) { - vector buf; - buf.resize(PATH_MAX); + vector buf(PATH_MAX); if (::realpath(path.c_str(), buf.data())) { return string(buf.data()); } @@ -273,8 +265,7 @@ string sc::real_path(const string& path) { } string sc::remove_accents(const string& text) { - vector buf; - buf.resize(text.size() * 2); + vector buf(text.size() * 2); size_t bufsize {buf.size()}; u8_normalize(UNINORM_NFD, reinterpret_cast(text.data()),