Skip to content

C++20移行 StaticStringをC++20で書き直す#2304

Merged
berryzplus merged 10 commits intosakura-editor:masterfrom
berryzplus:feature/rewrite_static_string
Jan 12, 2026
Merged

C++20移行 StaticStringをC++20で書き直す#2304
berryzplus merged 10 commits intosakura-editor:masterfrom
berryzplus:feature/rewrite_static_string

Conversation

@berryzplus
Copy link
Copy Markdown
Contributor

PR対象

  • アプリ(サクラエディタ本体)

カテゴリ

  • 改善

PR の背景

サクラエディタには独自の文字列系クラスがたくさんあり、長年課題になっていました。

仕様・動作説明

  • StaticStringの基本メンバーをC++標準に寄せます。
  • StaticStringの既存のC言語互換メンバーは残します。
  • CDataProfile でStaticString型設定値の読み書きに使っていた中間クラス StringBufferWstd::span<WCHAR> のエイリアスに変更し、メンテナンスが必要なコードを減らします。

本件も勝手にやります。

PR の影響範囲

テスト内容

関連 issue, PR

参考資料

定義済みのAssignメソッドを使うよう修正
変更前: オーバーフロー時、クラッシュ。
変更後: オーバーフロー時、バッファに収まるよう切り詰め。
検知された結果を使うかどうかは利用側の裁量に任せる。
C++11 In-Class Initializerを使いコンストラクターをdefaultにする
C++標準型との相互変換演算子群を定義する
初期値にNULLを指定できる意味はない。
explicitなので = "値" の書き方はできなくなった。
代入と文字数カウントにCランタイム関数を使うのをやめてconstexprにする。
EXPECT_THATスタイルに書き直す
@github-actions
Copy link
Copy Markdown

Test Results

658 tests   - 2   658 ✅  - 2   2m 16s ⏱️ -17s
 81 suites  - 1     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit db25411. ± Comparison against base commit e092b49.

This pull request removes 2 tests.
StringBufferW ‑ ctor
profile_data ‑ TryParse_StringBufferW

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 11, 2026

@berryzplus berryzplus marked this pull request as ready for review January 12, 2026 04:02

constexpr Me& operator = (std::wstring_view rhs) noexcept { assign(rhs); return *this; }
constexpr Me& operator = (const std::wstring& rhs) noexcept { assign(rhs); return *this; }
constexpr Me& operator = (const std::filesystem::path& path) noexcept { assign(path.wstring()); return *this; }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

う~む。

Suggested change
constexpr Me& operator = (const std::filesystem::path& path) noexcept { assign(path.wstring()); return *this; }
constexpr Me& operator = (const std::filesystem::path& path) noexcept { assign(path.native()); return *this; }
メソッド 戻り値型 説明
std::filesystem::path :: wstring() std::wstring 値を取得。(コピーする)
std::filesystem::path :: native() std::wstring& 値を取得。(コピーしない)

「どっち?」とやるなら native() なんだけど。

@berryzplus berryzplus merged commit f2c6735 into sakura-editor:master Jan 12, 2026
12 of 13 checks passed
@berryzplus berryzplus deleted the feature/rewrite_static_string branch January 12, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant