227f3cd9 [nostalgia/core/studio] Update itoa usages 20ff0f89 [ox/std] Rework itoa 4061b831 [ox/model] Remove broken global var 18bb5062 [ox/std] Add String::append(StringView), cleanup 6a4b4822 [nostalgia,studio] Fixes for Ox changes d2a3cfa7 [ox/std] Remove append operators from IString 7c4e2a65 [ox/std] Cleanup IString e30ebce4 [nostalgia] Add pyenv to .gitignore 7163947e [ox/std] Cleanup 0a0a6e30 [studio] Move UndoCommand implementation to its own file 97bc9332 [nostalgia/core] Fix TileSheetV1 to use PaletteV1 9caf7099 [keel] Fix for Ox change fda1280d [ox/std] Make substr always take and return a StringView 59aa4ad2 [cityhash] Cleanup 1a8afa1a [nostalgia/sample_project] Add missing type descriptor cdbc2d6c [olympic/studio] Move UndoCommand to its own file acd93337 [ox/std] Fix Integer assignment operator return cebd3b0a [ox/std] Fix Integer assignment operator return 43e2e215 [ox/std] Cleanup be1f9095 [ox/std] Make safeDelete constexpr 0f2c18d5 [ox/std] Add std::string(_view) variant of MaybeView git-subtree-dir: deps/nostalgia git-subtree-split: 227f3cd9f584039cfddad75f1fe1275ad6cac000
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
/*
|
|
* Copyright 2015 - 2024 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
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "basestringview.hpp"
|
|
|
|
namespace ox {
|
|
|
|
/**
|
|
* StringLiteral is used for functions that want to ensure that they are taking
|
|
* string literals, and not strings outside of the data section of the program
|
|
* that might get deleted.
|
|
* This type cannot force you to use it correctly, so don't give it something
|
|
* that is not a literal.
|
|
* If you do this:
|
|
* StringLiteral(str.c_str())
|
|
* the resulting segfault is on you.
|
|
*/
|
|
class StringLiteral: public detail::BaseStringView {
|
|
public:
|
|
constexpr StringLiteral() noexcept = default;
|
|
|
|
constexpr StringLiteral(StringLiteral const&sv) noexcept = default;
|
|
|
|
constexpr explicit StringLiteral(std::nullptr_t) noexcept {}
|
|
|
|
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
|
|
|
|
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
|
|
|
|
constexpr StringLiteral &operator=(StringLiteral const&other) noexcept {
|
|
if (&other != this) {
|
|
set(other.data(), other.len());
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
[[nodiscard]]
|
|
constexpr const char *c_str() const noexcept {
|
|
return data();
|
|
}
|
|
|
|
};
|
|
|
|
}
|