[ox] Fix remaining implicit conversion issues

This commit is contained in:
2023-06-06 23:32:23 -05:00
parent acf04665bc
commit 3fdfee33a9
50 changed files with 218 additions and 191 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 - 2022 gary@drinkingtea.net
* Copyright 2015 - 2023 gary@drinkingtea.net
*
* 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
@@ -29,8 +29,8 @@ PathIterator::PathIterator(CRStringView path): PathIterator(path.data(), path.by
* @return 0 if no error
*/
Error PathIterator::dirPath(char *out, std::size_t outSize) {
int idx = ox_lastIndexOf(m_path, '/', m_maxSize);
std::size_t size = idx + 1;
const auto idx = ox_lastIndexOf(m_path, '/', m_maxSize);
const auto size = static_cast<std::size_t>(idx + 1);
if (idx >= 0 && size < outSize) {
ox_memcpy(out, m_path, size);
out[size] = 0;
@@ -47,7 +47,7 @@ Error PathIterator::fileName(char *out, std::size_t outSize) {
auto idx = ox_lastIndexOf(m_path, '/', m_maxSize);
if (idx >= 0) {
idx++; // pass up the preceding /
std::size_t fileNameSize = ox_strlen(&m_path[idx]);
std::size_t fileNameSize = static_cast<size_t>(ox_strlen(&m_path[idx]));
if (fileNameSize < outSize) {
ox_memcpy(out, &m_path[idx], fileNameSize);
out[fileNameSize] = 0;
@@ -81,7 +81,7 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) {
if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
}
std::size_t end = substr - m_path;
const auto end = static_cast<size_t>(substr - m_path);
size = end - start;
// cannot fit the output in the output parameter
if (size >= pathOutSize || size == 0) {
@@ -105,14 +105,14 @@ Error PathIterator::next(char *pathOut, std::size_t pathOutSize) {
if (m_path[m_iterator] == '/') {
m_iterator++;
}
std::size_t start = m_iterator;
const auto start = m_iterator;
// end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next /
if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
}
std::size_t end = substr - m_path;
const auto end = static_cast<size_t>(substr - m_path);
size = end - start;
// cannot fit the output in the output parameter
if (size >= pathOutSize) {
@@ -152,14 +152,14 @@ Result<std::size_t> PathIterator::nextSize() const {
if (m_path[it] == '/') {
it++;
}
std::size_t start = it;
const auto start = it;
// end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next /
if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
}
std::size_t end = substr - m_path;
const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start;
}
it += size;
@@ -179,7 +179,7 @@ bool PathIterator::hasNext() const {
if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
}
std::size_t end = substr - m_path;
const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start;
}
return size > 0;
@@ -196,18 +196,18 @@ PathIterator PathIterator::next() const {
if (m_path[iterator] == '/') {
iterator++;
}
std::size_t start = iterator;
const auto start = iterator;
// end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next /
if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
}
std::size_t end = substr - m_path;
const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start;
}
iterator += size;
return PathIterator(m_path, m_maxSize, iterator + 1);
return {m_path, m_maxSize, iterator + 1};
}
const char *PathIterator::fullPath() const {