[ox] Update more C strings to StringViews
This commit is contained in:
		
							
								
								
									
										12
									
								
								deps/ox/src/ox/clargs/clargs.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								deps/ox/src/ox/clargs/clargs.cpp
									
									
									
									
										vendored
									
									
								
							@@ -37,32 +37,32 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool ClArgs::getBool(const char *arg, bool defaultValue) const noexcept {
 | 
					bool ClArgs::getBool(ox::CRStringView arg, bool defaultValue) const noexcept {
 | 
				
			||||||
	auto [value, err] = m_ints.at(arg);
 | 
						auto [value, err] = m_ints.at(arg);
 | 
				
			||||||
	return !err ? *value : defaultValue;
 | 
						return !err ? *value : defaultValue;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String ClArgs::getString(const char *arg, const char *defaultValue) const noexcept {
 | 
					String ClArgs::getString(ox::CRStringView arg, const char *defaultValue) const noexcept {
 | 
				
			||||||
	auto [value, err] = m_strings.at(arg);
 | 
						auto [value, err] = m_strings.at(arg);
 | 
				
			||||||
	return !err ? *value : defaultValue;
 | 
						return !err ? *value : defaultValue;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ClArgs::getInt(const char *arg, int defaultValue) const noexcept {
 | 
					int ClArgs::getInt(ox::CRStringView arg, int defaultValue) const noexcept {
 | 
				
			||||||
	auto [value, err] = m_ints.at(arg);
 | 
						auto [value, err] = m_ints.at(arg);
 | 
				
			||||||
	return !err ? *value : defaultValue;
 | 
						return !err ? *value : defaultValue;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Result<bool> ClArgs::getBool(const char *arg) const noexcept {
 | 
					Result<bool> ClArgs::getBool(ox::CRStringView arg) const noexcept {
 | 
				
			||||||
	oxRequire(out, m_bools.at(arg));
 | 
						oxRequire(out, m_bools.at(arg));
 | 
				
			||||||
	return *out;
 | 
						return *out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Result<String> ClArgs::getString(const char *argName) const noexcept {
 | 
					Result<String> ClArgs::getString(ox::CRStringView argName) const noexcept {
 | 
				
			||||||
	oxRequire(out, m_strings.at(argName));
 | 
						oxRequire(out, m_strings.at(argName));
 | 
				
			||||||
	return *out;
 | 
						return *out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Result<int> ClArgs::getInt(const char *arg) const noexcept {
 | 
					Result<int> ClArgs::getInt(ox::CRStringView arg) const noexcept {
 | 
				
			||||||
	oxRequire(out, m_ints.at(arg));
 | 
						oxRequire(out, m_ints.at(arg));
 | 
				
			||||||
	return *out;
 | 
						return *out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								deps/ox/src/ox/clargs/clargs.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								deps/ox/src/ox/clargs/clargs.hpp
									
									
									
									
										vendored
									
									
								
							@@ -22,17 +22,20 @@ class ClArgs {
 | 
				
			|||||||
	public:
 | 
						public:
 | 
				
			||||||
		ClArgs(int argc, const char **args) noexcept;
 | 
							ClArgs(int argc, const char **args) noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		bool getBool(const char *arg, bool defaultValue) const noexcept;
 | 
							[[nodiscard]]
 | 
				
			||||||
 | 
							bool getBool(ox::CRStringView arg, bool defaultValue) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		String getString(const char *argName, const char *defaultArg) const noexcept;
 | 
							[[nodiscard]]
 | 
				
			||||||
 | 
							String getString(ox::CRStringView argName, const char *defaultArg) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		int getInt(const char *arg, int defaultValue) const noexcept;
 | 
							[[nodiscard]]
 | 
				
			||||||
 | 
							int getInt(ox::CRStringView arg, int defaultValue) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Result<bool> getBool(const char *arg) const noexcept;
 | 
							Result<bool> getBool(ox::CRStringView arg) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Result<String> getString(const char *argName) const noexcept;
 | 
							Result<String> getString(ox::CRStringView argName) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Result<int> getInt(const char *arg) const noexcept;
 | 
							Result<int> getInt(ox::CRStringView arg) const noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								deps/ox/src/ox/fs/filesystem/directory.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								deps/ox/src/ox/fs/filesystem/directory.hpp
									
									
									
									
										vendored
									
									
								
							@@ -158,7 +158,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, Fi
 | 
				
			|||||||
		// determine if already exists
 | 
							// determine if already exists
 | 
				
			||||||
		auto name = nameBuff;
 | 
							auto name = nameBuff;
 | 
				
			||||||
		oxReturnError(path.get(name));
 | 
							oxReturnError(path.get(name));
 | 
				
			||||||
		auto childInode = find(name->c_str());
 | 
							auto childInode = find(PathIterator(*name));
 | 
				
			||||||
		if (!childInode.ok()) {
 | 
							if (!childInode.ok()) {
 | 
				
			||||||
			// if this is not the last item in the path and parents is disabled,
 | 
								// if this is not the last item in the path and parents is disabled,
 | 
				
			||||||
			// return an error
 | 
								// return an error
 | 
				
			||||||
@@ -174,7 +174,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, Fi
 | 
				
			|||||||
			Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
 | 
								Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
 | 
				
			||||||
			oxReturnError(child.init());
 | 
								oxReturnError(child.init());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			auto err = write(name->c_str(), childInode.value);
 | 
								auto err = write(PathIterator(*name), childInode.value);
 | 
				
			||||||
			if (err) {
 | 
								if (err) {
 | 
				
			||||||
				oxLogError(err);
 | 
									oxLogError(err);
 | 
				
			||||||
				// could not index the directory, delete it
 | 
									// could not index the directory, delete it
 | 
				
			||||||
@@ -202,16 +202,16 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode,
 | 
				
			|||||||
	if (path.next().hasNext()) { // not yet at target directory, recurse to next one
 | 
						if (path.next().hasNext()) { // not yet at target directory, recurse to next one
 | 
				
			||||||
		oxReturnError(path.get(name));
 | 
							oxReturnError(path.get(name));
 | 
				
			||||||
		oxTracef("ox::fs::Directory::write", "Attempting to write to next sub-Directory: {} of {}",
 | 
							oxTracef("ox::fs::Directory::write", "Attempting to write to next sub-Directory: {} of {}",
 | 
				
			||||||
		        name->c_str(), path.fullPath());
 | 
							         *name, path.fullPath());
 | 
				
			||||||
		oxRequire(nextChild, findEntry(*name));
 | 
							oxRequire(nextChild, findEntry(*name));
 | 
				
			||||||
		oxTracef("ox::fs::Directory::write", "{}: {}", name->c_str(), nextChild);
 | 
							oxTracef("ox::fs::Directory::write", "{}: {}", *name, nextChild);
 | 
				
			||||||
		if (nextChild) {
 | 
							if (nextChild) {
 | 
				
			||||||
			// reuse name because it is a rather large variable and will not be used again
 | 
								// reuse name because it is a rather large variable and will not be used again
 | 
				
			||||||
			// be attentive that this remains true
 | 
								// be attentive that this remains true
 | 
				
			||||||
			name = nullptr;
 | 
								name = nullptr;
 | 
				
			||||||
			return Directory(m_fs, nextChild).write(path.next(), inode, nameBuff);
 | 
								return Directory(m_fs, nextChild).write(path.next(), inode, nameBuff);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			oxTracef("ox::fs::Directory::write", "{} not found and not allowed to create it.", name->c_str());
 | 
								oxTracef("ox::fs::Directory::write", "{} not found and not allowed to create it.", *name);
 | 
				
			||||||
			return OxError(1, "File not found and not allowed to create it.");
 | 
								return OxError(1, "File not found and not allowed to create it.");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@@ -262,14 +262,14 @@ Error Directory<FileStore, InodeId_t>::remove(PathIterator path, FileName *nameB
 | 
				
			|||||||
	auto &name = *nameBuff;
 | 
						auto &name = *nameBuff;
 | 
				
			||||||
	oxReturnError(path.get(&name));
 | 
						oxReturnError(path.get(&name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oxTrace("ox::fs::Directory::remove", name.c_str());
 | 
						oxTrace("ox::fs::Directory::remove", name);
 | 
				
			||||||
	auto buff = m_fs.read(m_inodeId).template to<Buffer>();
 | 
						auto buff = m_fs.read(m_inodeId).template to<Buffer>();
 | 
				
			||||||
	if (buff.valid()) {
 | 
						if (buff.valid()) {
 | 
				
			||||||
		oxTrace("ox::fs::Directory::remove", "Found directory buffer.");
 | 
							oxTrace("ox::fs::Directory::remove", "Found directory buffer.");
 | 
				
			||||||
		for (auto i = buff->iterator(); i.valid(); i.next()) {
 | 
							for (auto i = buff->iterator(); i.valid(); i.next()) {
 | 
				
			||||||
			auto data = i->data();
 | 
								auto data = i->data();
 | 
				
			||||||
			if (data.valid()) {
 | 
								if (data.valid()) {
 | 
				
			||||||
				if (ox_strncmp(data->name, name.c_str(), name.len()) == 0) {
 | 
									if (data->name == name) {
 | 
				
			||||||
					oxReturnError(buff->free(i));
 | 
										oxReturnError(buff->free(i));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
@@ -308,7 +308,7 @@ Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
template<typename FileStore, typename InodeId_t>
 | 
					template<typename FileStore, typename InodeId_t>
 | 
				
			||||||
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
 | 
					Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
 | 
				
			||||||
	oxTrace("ox::fs::Directory::findEntry", name.c_str());
 | 
						oxTrace("ox::fs::Directory::findEntry", name);
 | 
				
			||||||
	auto buff = m_fs.read(m_inodeId).template to<Buffer>();
 | 
						auto buff = m_fs.read(m_inodeId).template to<Buffer>();
 | 
				
			||||||
	if (!buff.valid()) {
 | 
						if (!buff.valid()) {
 | 
				
			||||||
		oxTrace("ox::fs::Directory::findEntry::fail", "Could not findEntry directory buffer");
 | 
							oxTrace("ox::fs::Directory::findEntry::fail", "Could not findEntry directory buffer");
 | 
				
			||||||
@@ -318,9 +318,9 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
 | 
				
			|||||||
	for (auto i = buff->iterator(); i.valid(); i.next()) {
 | 
						for (auto i = buff->iterator(); i.valid(); i.next()) {
 | 
				
			||||||
		auto data = i->data();
 | 
							auto data = i->data();
 | 
				
			||||||
		if (data.valid()) {
 | 
							if (data.valid()) {
 | 
				
			||||||
			oxTracef("ox::fs::Directory::findEntry", "Comparing \"{}\" to \"{}\"", name.c_str(), data->name);
 | 
								oxTracef("ox::fs::Directory::findEntry", "Comparing \"{}\" to \"{}\"", name, data->name);
 | 
				
			||||||
			if (ox_strncmp(data->name, name.c_str(), MaxFileNameLength) == 0) {
 | 
								if (data->name == name) {
 | 
				
			||||||
				oxTracef("ox::fs::Directory::findEntry", "\"{}\" match found.", name.c_str());
 | 
									oxTracef("ox::fs::Directory::findEntry", "\"{}\" match found.", name);
 | 
				
			||||||
				return static_cast<InodeId_t>(data->inode);
 | 
									return static_cast<InodeId_t>(data->inode);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
@@ -342,7 +342,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(Path
 | 
				
			|||||||
	auto name = nameBuff;
 | 
						auto name = nameBuff;
 | 
				
			||||||
	oxReturnError(path.get(name));
 | 
						oxReturnError(path.get(name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oxRequire(v, findEntry(name->c_str()));
 | 
						oxRequire(v, findEntry(*name));
 | 
				
			||||||
	// recurse if not at end of path
 | 
						// recurse if not at end of path
 | 
				
			||||||
	if (auto p = path.next(); p.valid()) {
 | 
						if (auto p = path.next(); p.valid()) {
 | 
				
			||||||
		Directory dir(m_fs, v);
 | 
							Directory dir(m_fs, v);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@ Error PassThroughFS::mkdir(CRStringView path, bool recursive) noexcept {
 | 
				
			|||||||
	bool success = false;
 | 
						bool success = false;
 | 
				
			||||||
	const auto p = m_path / stripSlash(path);
 | 
						const auto p = m_path / stripSlash(path);
 | 
				
			||||||
	const auto u8p = p.u8string();
 | 
						const auto u8p = p.u8string();
 | 
				
			||||||
	oxTrace("ox::fs::PassThroughFS::mkdir", u8p.c_str());
 | 
						oxTrace("ox::fs::PassThroughFS::mkdir", std::bit_cast<const char*>(u8p.c_str()));
 | 
				
			||||||
	if (recursive) {
 | 
						if (recursive) {
 | 
				
			||||||
		std::error_code ec;
 | 
							std::error_code ec;
 | 
				
			||||||
		const auto isDir = std::filesystem::is_directory(p, ec);
 | 
							const auto isDir = std::filesystem::is_directory(p, ec);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user