Newer
Older
libkcpp / modules / include / kcpp_throwable.hpp
/**
 * @file kcpp_throwable.h
 * @brief Kantan C++ Library Throwable ヘッダファイル。
 * @copyright  2001 - 2024  Nomura Kei
 * @depends
 *   kcpp_object.hpp
 */
#ifndef KCPP_THROWABLE_HPP
#define KCPP_THROWABLE_HPP

#include <kcpp_object.hpp>

namespace kcpp
{

    class Throwable : public Object
    {
    public:
        // デフォルトコンストラクタ
        Throwable(const String &str = String()) noexcept;

        // コピーコンストラクタ
        Throwable(const String &str) noexcept;

        // ムーブコンストラクタ
        Throwable(String &&str) noexcept;

        // デストラクタ
        ~Throwable() noexcept;

        // コピー代入演算子
        String &operator=(const String &other) noexcept;

        // ムーブ代入演算子
        String &operator=(String &&obj) noexcept;

        // 文字列長を返す。
        int length() const noexcept;

        // 指定された位置の文字を返す。
        char charAt(int index) const;

        // 部分文字列を返す。
        String substring(int beginIndex, int endIndex) const;

        // 指定文字列が含まれるかい否かを返す。
        bool contains(const String &str) const noexcept;

        // 文字置換
        String replace(char oldChar, char newChar) const noexcept;

        // 文字列置換
        String replace(const String &regex, const String &replacement) const;

        // 文字列置換
        String replaceAll(const String &regex, const String &replacement) const;

        // 分割
        std::unique_ptr<String[]> split(const String &regex) const noexcept;

        // 先頭の文字列が一致するか
        bool startsWith(const String &prefix) const noexcept;

        // 末尾の文字列が一致するか
        bool endsWith(const String &suffix) const noexcept;

        // 小文字変換
        String toLowerCase() const noexcept;

        // 大文字変換
        String toUpperCase() const noexcept;

        // trim
        String trim() const noexcept;

        // 文字列表現取得
        String toString() const noexcept override;

        // 比較
        bool equals(const Object &obj) const noexcept override;

        // ハッシュコード
        int hashCode() const noexcept override;

        // クローン
        std::unique_ptr<Object> clone() const noexcept override;

        // 出力用
        friend std::ostream &operator<<(std::ostream &os, const String &str);

        // 入力用
        friend std::istream &operator>>(std::istream &is, String &str);

    protected:
        // 値
        std::unique_ptr<char[]> value;

        // 文字列の長さ
        int len;

        // データ設定関数
        void setValue(const char *str);
    };

} // namespace kcpp

#endif // KCPP_STRING_HPP