Skip to content

Conversation

@potrue
Copy link
Owner

@potrue potrue commented Aug 27, 2025

}
return num;
}
};

Choose a reason for hiding this comment

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

良いですが、long long を使わずオーバーフローをしないようにチェックしつつ計算するパターンも書いてみると勉強になると思います。

[英語版のドキュメント](https://en.cppreference.com/w/cpp/string/byte/isdigit.html)には
"isdigit and isxdigit are the only standard narrow character classification functions that are not affected by the currently installed C locale."
ってある。
この二つって別に両立するんでしょうか?それとも日本語版のドキュメントが間違ってるんですかね(分かる方教えてください。。。)

Choose a reason for hiding this comment

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

今回のようにASCII範囲の数字であればどの文字コードでも共通のコードポイントの認識です。

Copy link

Choose a reason for hiding this comment

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

ソースコードの文字コードと実行環境の文字コードという概念があって、実行環境の文字コードは ASCII を包含していることは保証はされていません。たとえば、EBCDIC という文字コードがあります。

isdigit の仕様を追っていくと、たしかに、C99 では isdigit はロケールによらず 5.2.1 節に列挙されている10文字を指しているので、文字コードが何かはともかく、文字としてその10文字です。
ドラフト: http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。貼っていただいたドラフトのp205にも
The only functions in 7.4 whose behavior is not affected by the current locale are isdigit and isxdigit.
とあるので、この二つはロケールに影響されなさそうですね。

{'8', 8},
{'9', 9},
};
string_view removeLeadingWhitespace(string_view s) {
Copy link

Choose a reason for hiding this comment

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

自分ならメンバー変数やメンバー関数のあいだに空行を空けると思います。

Copy link

@ryosuketc ryosuketc left a comment

Choose a reason for hiding this comment

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

よいと思います。long long を使わない方法についてはたぶんこの問題のポイントのひとつなのでやっておいたほうが良さそうです。

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.

7 participants