-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overhaul String Documentation #68838
Overhaul String Documentation #68838
Conversation
1192c0a
to
48bf9e9
Compare
48bf9e9
to
9e49e3d
Compare
You may take a second look, although this is still a draft. |
9e49e3d
to
34c367e
Compare
34c367e
to
42ad84a
Compare
doc/classes/String.xml
Outdated
[/codeblock] | ||
</description> | ||
</method> | ||
<method name="is_valid_int" qualifiers="const"> | ||
<return type="bool" /> | ||
<description> | ||
Returns [code]true[/code] if this string contains a valid integer. | ||
Returns [code]true[/code] if this string represents a valid [int]. A valid integer only contains digits, and may be prefixed with a positive ([code]+[/code]) or negative ([code]-[/code]) sign. See also [method to_int]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to refer to the int class IMO. A valid integer is not a valid [int] - it doesn't support multiple unary operators or separators. This is for GDScript, anyway... It also supports arbitrarily big numbers, not just 64-bit.
Or we could perhaps add a note about it.
Same for is_valid_float()
, there are even more inconsistencies there.
Look what I had to do when I wanted to catch up GDScript's highlighter to accept all valid floats/ints and halt otherwise 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure. The GDScript compiler is one thing and the int type is another. Many different languages may define their own special way to write an integer, but at its core, in Godot an int is an integer and a float is a floating-point value. I may or may not make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was GDScript-specific here - anyway, since these methods have their own generic rules for what is a valid int/float, I'd say it's better to just state those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it, one method was renamed from 3.x. It used to be called is_valid_integer
. The current name is a bit of a misnomer because it could really just go above the 64-bit limit if someone wanted to use it for that purpose... So it's not just about the Variant Type called int
, it's any kind of integer.
b1e06b7
to
1511d3d
Compare
1511d3d
to
1ce2bd6
Compare
1ce2bd6
to
bf404e9
Compare
1d3fc5c
to
3f76a27
Compare
Settles it. At this point it is pretty much ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last one fr this time
[/codeblock] | ||
</description> | ||
</method> | ||
<method name="is_valid_int" qualifiers="const"> | ||
<return type="bool" /> | ||
<description> | ||
Returns [code]true[/code] if this string contains a valid integer. | ||
Returns [code]true[/code] if this string represents a valid integer. A valid integer only contains digits, and may be prefixed with a positive ([code]+[/code]) or negative ([code]-[/code]) sign. See also [method to_int]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma before "and" not necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm putting it here this time to nicely split the requirements for an integer.
@@ -124,7 +149,7 @@ | |||
<param index="1" name="from" type="int" default="0" /> | |||
<param index="2" name="to" type="int" default="0" /> | |||
<description> | |||
Returns the number of occurrences of substring [param what] between [param from] and [param to] positions. If [param from] and [param to] equals 0 the whole string will be used. If only [param to] equals 0 the remained substring will be used. | |||
Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions. If [param to] is 0, the search continues until the end of the string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numbers not surrounded by code pt. 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, actually, do not worry about surrounding numbers in code too much. Doing it here ends up probably filling the description with more codeblocks and padding than necessary. Will keep open for further evaluation.
b3e2a00
to
637e386
Compare
637e386
to
c5f2272
Compare
Updated this PR to add a boolean context note in the leading description. This note is present in several other Variant types, so it only makes sense to include it here as well, unless there are some objections to it. |
493f61a
to
14cc3a3
Compare
While looking at the String class today, I noticed that some of the operator descriptions say "left string" and some say "this string". The latter felt confusing. My thought is, we should improve the way operators are presented in the docs overall, and alongside that visit all operator documentation to be explicit about "left" and "right". I also saw "both" being misused - it can't be used like "if both strings have something in common" - must be "if the two strings have something in common". |
Not sure. All operators act from a base and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks everyone for the reviews!
14cc3a3
to
9e77dce
Compare
9e77dce
to
6164497
Compare
6164497
to
3f2d0cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM minor a nit pick, but it's probably fine to leave as is.
3f2d0cd
to
3b71d85
Compare
Thanks! |
Adding this one to the collection of #67072, #67100, #67208, #67718,... #67880 and #68560... and #68649...
Related to #68217.
This PR modifies the String documentation extensively in an attempt to improve its quality and make old and new users more at ease while exploring the enormous bloat of a Variant that String is.
Because this is core content that has probably existed since the beginning of time, a review is particularly more appreciated than usual.
Here a big list of changes. Someone reading this may take it as a future point of reference. Not just that, but some information deemed important by the maintainers could have been lost during the rewrite. Criticism is encouraged.
Do note that some exceptions or unexplained changes may be present all around. These are typically done to improve the flow of the sentence.
General
Added more detail to the leading description;
Made the wording match how other classes are documented a lot more closely;
Made use of
[param]
and several other strong references more often;Linked several related methods to each other.
Included several more links to external websites;
Stripped awkward, needlessly long sentences;
Changed words where it felt necessary, where they could be mistaken for another concept of Godot's API, where technical terms are more appropriate. For example:
-You're not passing a generic String parameter, several method refer to this very String you're calling it from.
Modified examples extensively, with the main goal to improve readability and variety:
# Prints "5"
-># Prints 5
);print()
;Removed quotes when referring to single characters;
Removed "case-sensitive" in original method (
match
, etc.);Highlighted "case-insensitive" more in method variations (
matchn
, etc.).Methods
bigrams
bin_to_int
What for?
capitalize
Describing it like ASCII tables are quest items.
casecmp_to
nocasecmp_to
naturalnocasecmp_to
naturalnocasecmp_to
's specialty.contains
in
operator with String fromfind()
to here.find
in
operator with String from here tocontains()
.get_base_dir
get_basename
Added examples.
get_extension
Modified examples to improve variation.
get_slice_count
Changed description to imply that no actual splitting (processing an array of substring slices) is executed.
hash
Reduced verbosity of extra note considerably.
indent
"# "
."O-o... ok...?
is_relative_path
is_subsequence_of
is_subsequence_ofn
true
if this string is a subsequence of the given string."Ok, cool- Err, I mean, what!? What is a subsequence!?
is_valid_filename
Merged paragraph to the first.
is_valid_float
is_valid_hex_number
is_valid_html_color
is_valid_int
is_valid_ip_address
Added IPv6 address example.
join
Modified and expanded example.
json_escape
Detail what to use to unescape the string, if necessary.
left
right
Changed example string for better demostration.
length
Detail return value for empty strings.
md5_buffer
md5_text
sha1_buffer
sha1_text
sha256_buffer
sha256_text
Add external links for MD5, SHA-1 and SHA-256.
num_int64
num_scientific
num_uint64
Added missing documentation.
path_join
Reworded entirely to mitigate the general confusion of what this method actually does (it's really, really simple, guys).
repeat
Detailed what happens when parameter is lower or equal to 0.
rsplit
split
simplify_path
Added much more detail and example.
split_floats
Added more examples.
strip_edges
Described
left
andright
parameters in separate paragraph.to_ascii_buffer
Massively reduced verbosity.
to_float
to_int
Add example result for invalid string.
uri_decode
uri_encode
Modified examples to reference the online documentation.
validate_node_name
Added missing Scene Unique Node symbol
(I wish I could forget about them, too but they're here to stay).Feedback is very, very welcome.