Compare commits
5 Commits
61aa1ea11f
...
1ac7629459
Author | SHA1 | Date |
---|---|---|
Bananymous | 1ac7629459 | |
Bananymous | 95681a7a05 | |
Bananymous | d7b8458a56 | |
Bananymous | 67dfe0bcf3 | |
Bananymous | b1869bced4 |
|
@ -26,10 +26,15 @@ namespace BAN
|
|||
~String() { clear(); }
|
||||
|
||||
template<typename... Args>
|
||||
static String formatted(const char* format, const Args&... args)
|
||||
static BAN::ErrorOr<String> formatted(const char* format, Args&&... args)
|
||||
{
|
||||
size_type length = 0;
|
||||
BAN::Formatter::print([&](char) { length++; }, format, BAN::forward<Args>(args)...);
|
||||
|
||||
String result;
|
||||
BAN::Formatter::print([&](char c){ MUST(result.push_back(c)); }, format, args...);
|
||||
TRY(result.reserve(length));
|
||||
BAN::Formatter::print([&](char c){ MUST(result.push_back(c)); }, format, BAN::forward<Args>(args)...);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,37 @@ namespace BAN
|
|||
return {};
|
||||
}
|
||||
|
||||
BAN::Optional<size_type> rfind(char ch) const
|
||||
{
|
||||
for (size_type i = m_size; i > 0; i--)
|
||||
if (m_data[i - 1] == ch)
|
||||
return i - 1;
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::Optional<size_type> rfind(bool(*comp)(char)) const
|
||||
{
|
||||
for (size_type i = m_size; i > 0; i--)
|
||||
if (comp(m_data[i - 1]))
|
||||
return i - 1;
|
||||
return {};
|
||||
}
|
||||
|
||||
constexpr bool starts_with(BAN::StringView target) const
|
||||
{
|
||||
if (target.size() > m_size)
|
||||
return false;
|
||||
for (size_type i = 0; i < m_size - target.size(); i++)
|
||||
{
|
||||
bool valid = true;
|
||||
for (size_type j = 0; j < target.size() && valid; j++)
|
||||
valid = (m_data[i + j] == target[j]);
|
||||
if (valid)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr bool contains(char ch) const
|
||||
{
|
||||
for (size_type i = 0; i < m_size; i++)
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Kernel
|
|||
|
||||
FramebufferDevice::FramebufferDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev, paddr_t paddr, uint32_t width, uint32_t height, uint32_t pitch, uint8_t bpp)
|
||||
: CharacterDevice(mode, uid, gid)
|
||||
, m_name(BAN::String::formatted("fb{}", minor(rdev)))
|
||||
, m_name(MUST(BAN::String::formatted("fb{}", minor(rdev))))
|
||||
, m_rdev(rdev)
|
||||
, m_video_memory_paddr(paddr)
|
||||
, m_width(width)
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<void> ProcFileSystem::on_process_create(Process& process)
|
||||
{
|
||||
auto path = BAN::String::formatted("{}", process.pid());
|
||||
auto path = TRY(BAN::String::formatted("{}", process.pid()));
|
||||
auto inode = TRY(ProcPidInode::create_new(process, *this, 0555, process.credentials().ruid(), process.credentials().rgid()));
|
||||
TRY(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path));
|
||||
return {};
|
||||
|
@ -37,7 +37,7 @@ namespace Kernel
|
|||
|
||||
void ProcFileSystem::on_process_delete(Process& process)
|
||||
{
|
||||
auto path = BAN::String::formatted("{}", process.pid());
|
||||
auto path = MUST(BAN::String::formatted("{}", process.pid()));
|
||||
|
||||
auto inode = MUST(root_inode()->find_inode(path));
|
||||
static_cast<ProcPidInode*>(inode.ptr())->cleanup();
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel::Input
|
|||
PS2Device::PS2Device(PS2Controller& controller)
|
||||
: CharacterDevice(0440, 0, 901)
|
||||
, m_rdev(makedev(DeviceNumber::Input, DevFileSystem::get().get_next_input_device()))
|
||||
, m_name(BAN::String::formatted("input{}", minor(m_rdev)))
|
||||
, m_name(MUST(BAN::String::formatted("input{}", minor(m_rdev))))
|
||||
, m_controller(controller)
|
||||
{ }
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ namespace Kernel
|
|||
const uint32_t target_ack = m_send_window.start_seq + m_send_window.data_size;
|
||||
m_semaphore.unblock();
|
||||
|
||||
while (m_send_window.start_seq < target_ack)
|
||||
while (m_send_window.current_ack < target_ack)
|
||||
{
|
||||
if (m_state != State::Established)
|
||||
return return_with_maybe_zero();
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Kernel
|
|||
, m_first_block(first_block)
|
||||
, m_last_block(last_block)
|
||||
, m_attributes(attr)
|
||||
, m_name(BAN::String::formatted("{}{}", name_prefix, index))
|
||||
, m_name(MUST(BAN::String::formatted("{}{}", name_prefix, index)))
|
||||
, m_rdev(makedev(major(device->rdev()), index))
|
||||
{
|
||||
memcpy(m_label, label, sizeof(m_label));
|
||||
|
|
|
@ -179,11 +179,10 @@ namespace Kernel
|
|||
|
||||
SerialTTY::SerialTTY(Serial serial)
|
||||
: TTY(0600, 0, 0)
|
||||
, m_name(MUST(BAN::String::formatted("ttyS{}", minor(rdev()))))
|
||||
, m_serial(serial)
|
||||
, m_rdev(next_rdev())
|
||||
{
|
||||
m_name = BAN::String::formatted("ttyS{}", minor(rdev()));
|
||||
}
|
||||
{}
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<SerialTTY>> SerialTTY::create(Serial serial)
|
||||
{
|
||||
|
|
|
@ -43,11 +43,10 @@ namespace Kernel
|
|||
|
||||
VirtualTTY::VirtualTTY(TerminalDriver* driver)
|
||||
: TTY(0600, 0, 0)
|
||||
, m_name(MUST(BAN::String::formatted("tty{}", minor(rdev()))))
|
||||
, m_terminal_driver(driver)
|
||||
, m_rdev(next_rdev())
|
||||
{
|
||||
m_name = BAN::String::formatted("tty{}", minor(rdev()));
|
||||
|
||||
m_width = m_terminal_driver->width();
|
||||
m_height = m_terminal_driver->height();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
|
|||
if (command[i] == '?')
|
||||
{
|
||||
i++;
|
||||
return BAN::String::formatted("{}", last_return);
|
||||
return MUST(BAN::String::formatted("{}", last_return));
|
||||
}
|
||||
if (isalnum(command[i]))
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ Config parse_config()
|
|||
return config;
|
||||
}
|
||||
|
||||
auto config_path = BAN::String::formatted("{}/.config/WindowServer.conf", home_env);
|
||||
auto config_path = MUST(BAN::String::formatted("{}/.config/WindowServer.conf", home_env));
|
||||
FILE* fconfig = fopen(config_path.data(), "r");
|
||||
if (!fconfig)
|
||||
{
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace LibImage
|
|||
const auto b = p[0] + (p[1] * -2.5) + (p[2] * 2.0) + (p[3] * -0.5);
|
||||
const auto c = (p[0] * -0.5) + (p[2] * 0.5);
|
||||
const auto d = p[1];
|
||||
return (a * x * x * x) + (b * x * x) + (c * x) + d;
|
||||
return ((a * x + b) * x + c) * x + d;
|
||||
};
|
||||
|
||||
for (uint64_t y = 0; y < new_height; y++)
|
||||
|
|
|
@ -72,14 +72,14 @@ BAN::String build_access_string(mode_t mode)
|
|||
|
||||
BAN::String build_hard_links_string(nlink_t links)
|
||||
{
|
||||
return BAN::String::formatted("{}", links);
|
||||
return MUST(BAN::String::formatted("{}", links));
|
||||
}
|
||||
|
||||
BAN::String build_owner_name_string(uid_t uid)
|
||||
{
|
||||
struct passwd* passwd = getpwuid(uid);
|
||||
if (passwd == nullptr)
|
||||
return BAN::String::formatted("{}", uid);
|
||||
return MUST(BAN::String::formatted("{}", uid));
|
||||
return BAN::String(BAN::StringView(passwd->pw_name));
|
||||
}
|
||||
|
||||
|
@ -87,13 +87,13 @@ BAN::String build_owner_group_string(gid_t gid)
|
|||
{
|
||||
struct group* grp = getgrgid(gid);
|
||||
if (grp == nullptr)
|
||||
return BAN::String::formatted("{}", gid);
|
||||
return MUST(BAN::String::formatted("{}", gid));
|
||||
return BAN::String(BAN::StringView(grp->gr_name));
|
||||
}
|
||||
|
||||
BAN::String build_size_string(off_t size)
|
||||
{
|
||||
return BAN::String::formatted("{}", size);
|
||||
return MUST(BAN::String::formatted("{}", size));
|
||||
}
|
||||
|
||||
BAN::String build_month_string(BAN::Time time)
|
||||
|
@ -104,15 +104,15 @@ BAN::String build_month_string(BAN::Time time)
|
|||
|
||||
BAN::String build_day_string(BAN::Time time)
|
||||
{
|
||||
return BAN::String::formatted("{}", time.day);
|
||||
return MUST(BAN::String::formatted("{}", time.day));
|
||||
}
|
||||
|
||||
BAN::String build_time_string(BAN::Time time)
|
||||
{
|
||||
static uint32_t current_year = ({ timespec real_time; clock_gettime(CLOCK_REALTIME, &real_time); BAN::from_unix_time(real_time.tv_sec).year; });
|
||||
if (time.year != current_year)
|
||||
return BAN::String::formatted("{}", time.year);
|
||||
return BAN::String::formatted("{2}:{2}", time.hour, time.minute);
|
||||
return MUST(BAN::String::formatted("{}", time.year));
|
||||
return MUST(BAN::String::formatted("{2}:{2}", time.hour, time.minute));
|
||||
}
|
||||
|
||||
int list_directory(const BAN::String& path, config_t config)
|
||||
|
@ -213,7 +213,7 @@ int list_directory(const BAN::String& path, config_t config)
|
|||
GET_ENTRY_STRING(day, time);
|
||||
GET_ENTRY_STRING(time, time);
|
||||
|
||||
full_entry.full_name = BAN::String::formatted("{}{}\e[m", entry_color(entry.st.st_mode), entry.name);
|
||||
full_entry.full_name = MUST(BAN::String::formatted("{}{}\e[m", entry_color(entry.st.st_mode), entry.name));
|
||||
|
||||
MUST(full_entries.push_back(BAN::move(full_entry)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue