mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-27 17:11:00 +01:00
pf2: skeleton str api
This commit is contained in:
parent
60ea1dade2
commit
3107ec0127
@ -22,6 +22,7 @@
|
||||
#include <vapours/svc.hpp>
|
||||
|
||||
#include <vapours/prfile2/prfile2_common.hpp>
|
||||
#include <vapours/prfile2/prfile2_str.hpp>
|
||||
#include <vapours/prfile2/prfile2_system.hpp>
|
||||
#include <vapours/prfile2/pdm/prfile2_pdm_api.hpp>
|
||||
#include <vapours/prfile2/pdm/prfile2_pdm_disk_management.hpp>
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <vapours/prfile2/prfile2_build_config.hpp>
|
||||
#include <vapours/prfile2/pf/prfile2_pf_config.hpp>
|
||||
#include <vapours/prfile2/pf/prfile2_pf_api_common.hpp>
|
||||
#include <vapours/prfile2/prfile2_wide_string.hpp>
|
||||
|
||||
namespace ams::prfile2 {
|
||||
|
||||
|
65
libraries/libvapours/include/vapours/prfile2/prfile2_str.hpp
Normal file
65
libraries/libvapours/include/vapours/prfile2/prfile2_str.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours/prfile2/prfile2_common.hpp>
|
||||
|
||||
namespace ams::prfile2::str {
|
||||
|
||||
enum CodeMode {
|
||||
CodeMode_Invalid = 0,
|
||||
CodeMode_Local = 1,
|
||||
CodeMode_Unicode = 2,
|
||||
};
|
||||
|
||||
enum TargetString {
|
||||
TargetString_Head = 1,
|
||||
TargetString_Tail = 2,
|
||||
};
|
||||
|
||||
struct String {
|
||||
const char *head;
|
||||
const char *tail;
|
||||
CodeMode code_mode;
|
||||
};
|
||||
|
||||
pf::Error Initialize(String *str, const char *s, CodeMode code_mode);
|
||||
|
||||
void SetCodeMode(String *str, CodeMode code_mode);
|
||||
CodeMode GetCodeMode(const String *str);
|
||||
|
||||
char *GetPos(String *str, TargetString target);
|
||||
void MovePos(String *str, s16 num_char);
|
||||
|
||||
u16 GetLength(String *str);
|
||||
u16 GetNumChar(String *str, TargetString target);
|
||||
|
||||
int Compare(const String *str, const char *rhs);
|
||||
int Compare(const String *str, const WideChar *rhs);
|
||||
|
||||
/* TODO: StrNCmp */
|
||||
/* TODO: ToUpperNStr */
|
||||
|
||||
constexpr bool IsNull(const String *str) {
|
||||
return str->head == nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ams::prfile2 {
|
||||
|
||||
using String = str::String;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours/prfile2/prfile2_common.hpp>
|
||||
|
||||
namespace ams::prfile2 {
|
||||
|
||||
using WideChar = u16;
|
||||
|
||||
size_t w_strlen(const WideChar *s);
|
||||
size_t w_strnlen(const WideChar *s, size_t length);
|
||||
|
||||
WideChar *w_strcpy(WideChar *dst, const WideChar *src);
|
||||
WideChar *w_strncpy(WideChar *dst, const WideChar *src, size_t length);
|
||||
|
||||
int w_strcmp(const WideChar *lhs, const WideChar *rhs);
|
||||
int w_strncmp(const WideChar *lhs, const WideChar *rhs, size_t length);
|
||||
|
||||
}
|
110
libraries/libvapours/source/prfile2/prfile2_str.cpp
Normal file
110
libraries/libvapours/source/prfile2/prfile2_str.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
|
||||
#include <stratosphere.hpp>
|
||||
#elif defined(ATMOSPHERE_IS_MESOSPHERE)
|
||||
#include <mesosphere.hpp>
|
||||
#elif defined(ATMOSPHERE_IS_EXOSPHERE)
|
||||
#include <exosphere.hpp>
|
||||
#else
|
||||
#include <vapours.hpp>
|
||||
#endif
|
||||
|
||||
namespace ams::prfile2::str {
|
||||
|
||||
namespace {
|
||||
|
||||
/* TODO: Where does this come from? */
|
||||
/* It's maximum path length * 2, but where should the definition live? */
|
||||
constexpr inline size_t StringLengthMax = 520;
|
||||
|
||||
}
|
||||
|
||||
pf::Error Initialize(String *str, const char *s, CodeMode code_mode) {
|
||||
/* Check parameters. */
|
||||
if (str == nullptr || s == nullptr) {
|
||||
return pf::Error_InvalidParameter;
|
||||
}
|
||||
|
||||
/* Initialize the string. */
|
||||
switch (code_mode) {
|
||||
case CodeMode_Local:
|
||||
{
|
||||
str->head = s;
|
||||
str->tail = s + sizeof(char) * strnlen(s, StringLengthMax);
|
||||
}
|
||||
break;
|
||||
case CodeMode_Unicode:
|
||||
{
|
||||
str->head = s;
|
||||
str->tail = s + sizeof(WideChar) * w_strnlen(reinterpret_cast<const WideChar *>(s), StringLengthMax);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return pf::Error_InvalidParameter;
|
||||
}
|
||||
|
||||
/* Set the code mode. */
|
||||
str->code_mode = code_mode;
|
||||
|
||||
return pf::Error_Ok;
|
||||
}
|
||||
|
||||
void SetCodeMode(String *str, CodeMode code_mode) {
|
||||
str->code_mode = code_mode;
|
||||
}
|
||||
|
||||
CodeMode GetCodeMode(const String *str) {
|
||||
return str->code_mode;
|
||||
}
|
||||
|
||||
char *GetPos(String *str, TargetString target) {
|
||||
if (target == TargetString_Head) {
|
||||
return const_cast<char *>(str->head);
|
||||
} else {
|
||||
return const_cast<char *>(str->tail);
|
||||
}
|
||||
}
|
||||
|
||||
void MovePos(String *str, s16 num_char) {
|
||||
AMS_UNUSED(str, num_char);
|
||||
AMS_ABORT("TODO: oem charset");
|
||||
}
|
||||
|
||||
u16 GetLength(String *str) {
|
||||
if (str->code_mode == CodeMode_Unicode) {
|
||||
return (str->tail - str->head) / sizeof(WideChar);
|
||||
} else {
|
||||
return (str->tail - str->head) / sizeof(char);
|
||||
}
|
||||
}
|
||||
|
||||
u16 GetNumChar(String *str, TargetString target) {
|
||||
AMS_UNUSED(str, target);
|
||||
AMS_ABORT("TODO: oem charset");
|
||||
}
|
||||
|
||||
int Compare(const String *str, const char *rhs) {
|
||||
AMS_UNUSED(str, rhs);
|
||||
AMS_ABORT("TODO: oem charset");
|
||||
}
|
||||
|
||||
int Compare(const String *str, const WideChar *rhs) {
|
||||
AMS_UNUSED(str, rhs);
|
||||
AMS_ABORT("TODO: oem charset");
|
||||
}
|
||||
|
||||
}
|
109
libraries/libvapours/source/prfile2/prfile2_wide_string.cpp
Normal file
109
libraries/libvapours/source/prfile2/prfile2_wide_string.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
|
||||
#include <stratosphere.hpp>
|
||||
#elif defined(ATMOSPHERE_IS_MESOSPHERE)
|
||||
#include <mesosphere.hpp>
|
||||
#elif defined(ATMOSPHERE_IS_EXOSPHERE)
|
||||
#include <exosphere.hpp>
|
||||
#else
|
||||
#include <vapours.hpp>
|
||||
#endif
|
||||
|
||||
namespace ams::prfile2 {
|
||||
|
||||
size_t w_strlen(const WideChar *s) {
|
||||
const WideChar *cur;
|
||||
for (cur = s; *cur != 0; ++cur) {
|
||||
/* ... */
|
||||
}
|
||||
return cur - s;
|
||||
}
|
||||
|
||||
size_t w_strnlen(const WideChar *s, size_t length) {
|
||||
const WideChar *cur;
|
||||
for (cur = s; *cur != 0 && length != 0; ++cur, --length) {
|
||||
/* ... */
|
||||
}
|
||||
return cur - s;
|
||||
}
|
||||
|
||||
WideChar *w_strcpy(WideChar *dst, const WideChar *src) {
|
||||
WideChar * const ret = dst;
|
||||
while (true) {
|
||||
const auto c = *(src++);
|
||||
*(dst++) = c;
|
||||
|
||||
if (c == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
WideChar *w_strncpy(WideChar *dst, const WideChar *src, size_t length) {
|
||||
WideChar * const ret = dst;
|
||||
while (length > 1) {
|
||||
const auto c = *(src++);
|
||||
*(dst++) = c;
|
||||
|
||||
if (c == 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (length == 1) {
|
||||
*(dst++) = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int w_strcmp(const WideChar *lhs, const WideChar *rhs) {
|
||||
WideChar l, r;
|
||||
while (true) {
|
||||
l = *(lhs++);
|
||||
r = *(rhs++);
|
||||
if (l == 0 || r == 0 || l != r) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return l - r;
|
||||
}
|
||||
|
||||
int w_strncmp(const WideChar *lhs, const WideChar *rhs, size_t length) {
|
||||
if (length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WideChar l, r;
|
||||
while (true) {
|
||||
l = *(lhs++);
|
||||
r = *(rhs++);
|
||||
if (l == 0 || r == 0 || l != r) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((--length) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return l - r;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user