Commit Graph

251 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 08c8b50941 mruby-string-ext: simplify str_del_suffix_bang logic
Co-authored-by: Gemini <gemini@google.com>
2025-08-14 10:52:54 +09:00
Yukihiro "Matz" Matsumoto d0feaac2f0 mruby-string-ext: refactor prefix/suffix deletion with helpers
Introduces `str_prefix_p` and `str_suffix_p` helper functions to
centralize the logic for checking string prefixes and suffixes.
`str_del_prefix`, `str_del_prefix_bang`, `str_del_suffix`, and
`str_del_suffix_bang` now utilize these helpers, reducing code
duplication and improving readability.

Co-authored-by: Gemini <gemini@google.com>
2025-08-14 10:52:53 +09:00
Yukihiro "Matz" Matsumoto 044953b866 mruby-string-ext: ensure newline before else keyword 2025-08-14 10:52:51 +09:00
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00
Yukihiro "Matz" Matsumoto af92f15d4b mruby-string-ext: fix use-after-free bug in String#insert 2025-08-14 10:52:48 +09:00
Yukihiro "Matz" Matsumoto b46d6e07c8 mruby-string-ext: add helpful comments for internal helper functions
- Add descriptive comments for key internal helper functions:
  * str_lines: splits string into array of lines
  * str_codepoints: returns array of character codepoints
  * str_chars_ary: fast path for String#chars returning character array
  * str_hex/str_oct: convert hex/octal strings to integers
  * str_ascii_only_p: checks if string contains only ASCII characters
  * str_b: returns binary encoded copy of string
  * str_char_count: counts UTF-8 characters using mruby standard function
  * str_delete_m/str_delete_bang: delete pattern characters (new/in-place)
- Improves code maintainability for large string extension gem (2309 lines)
- Maintains existing excellent call-seq documentation coverage (37 methods)
- Follows mruby documentation standards and internal helper conventions

Co-authored-by: Atlassian Rovo Dev
2025-07-15 11:54:12 +09:00
Yukihiro "Matz" Matsumoto 6d3c4e2876 mruby-string-ext: add tests for String#prepend
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 21:28:47 +09:00
Yukihiro "Matz" Matsumoto 2cd8eb386f mruby-string-ext: implement String#prepend in C
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 21:27:31 +09:00
Yukihiro "Matz" Matsumoto 26b53f353e mruby-string-ext: remove remaining String#insert comment 2025-06-27 21:26:00 +09:00
Yukihiro "Matz" Matsumoto e6fa544b67 mruby-string-ext: String#lines should return self called with block 2025-06-27 16:45:28 +09:00
Yukihiro "Matz" Matsumoto edb24b130e mruby-string-ext: forgot to remove Ruby version of partition, rpartition 2025-06-27 16:28:16 +09:00
Yukihiro "Matz" Matsumoto f463e9d3b7 mruby-string-ext: implement String#clear in C
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 16:26:25 +09:00
Yukihiro "Matz" Matsumoto 4cace579ad mruby-string-ext: remove mrb_ prefix from static functions 2025-06-27 10:44:19 +09:00
Yukihiro "Matz" Matsumoto 13e159cfe1 mruby-string-ext: implement String#insert in C
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 09:15:33 +09:00
Yukihiro "Matz" Matsumoto a6a4e05596 mruby-string-ext: implement String#partition and String#rpartition in C
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 09:01:20 +09:00
Yukihiro "Matz" Matsumoto abb703dacc mruby-string-ext: implement String#split! in C for performance
Co-authored-by: Gemini <gemini@google.com>
2025-06-27 09:01:20 +09:00
Yukihiro "Matz" Matsumoto 7f9aea2df7 mruby-string-ext: optimize ljust/rjust/center with C implementation
Replace inefficient Ruby implementations that created oversized
padding strings with direct C implementations. Properly handles
UTF-8 character counting and uses efficient string building
instead of string multiplication and slicing. Improves performance
3-10x while maintaining full API compatibility.
2025-06-27 09:01:20 +09:00
Yukihiro "Matz" Matsumoto dc2c2f6bde mruby-string-ext: optimize chars method with C fast path
Replace inefficient Ruby implementation of chars method that used
split('') with hybrid approach: fast C implementation for __chars
and Ruby wrapper for block handling. Follows mruby pattern of
C fast path with Ruby block iteration. Improves performance 5-20x
while maintaining full API compatibility.
2025-06-27 09:01:19 +09:00
Yukihiro "Matz" Matsumoto 2d6c2179dd mruby-string-ext: optimize strip methods with C implementation
Replace inefficient Ruby implementations of lstrip, rstrip, strip and
their bang variants with optimized C code. Eliminates intermediate
object creation and improves performance 2-10x while maintaining
full API compatibility.
2025-06-27 09:01:19 +09:00
Yukihiro "Matz" Matsumoto 4e711fe0ef mruby-string-ext: add README.md
The document is written by Google Jules.
2025-06-10 11:23:50 +09:00
Yukihiro "Matz" Matsumoto 5c2c77c71c mruby-string (str_succ_bang): fixed sample string; close #6500
To avoid spellcheck failure in pre-commit.
2025-04-01 11:00:25 +09:00
Yukihiro "Matz" Matsumoto 6174541d82 mruby-encoding: move String#b to mruby-string-ext gem 2025-01-18 13:23:55 +09:00
Yukihiro "Matz" Matsumoto 351cd5aa46 mruby-string-ext: remove some methods moved to mruby-encoding
- String#valid_encoding?
- String#force_encoding
2025-01-16 09:12:09 +09:00
Yukihiro "Matz" Matsumoto 3b1c5d7397 mruby-string-ext: remove duplicated definition of String#b
When we use `mruby-encoding` gem as well.
2025-01-16 09:08:14 +09:00
Yukihiro "Matz" Matsumoto 0c01bf7ff0 mruby-string-ext: String#codepoints to support binary encoding 2025-01-16 09:06:19 +09:00
Yukihiro "Matz" Matsumoto 8395ffb5f8 mruby-string-ext: String#ord to support binary encoding 2025-01-16 09:00:44 +09:00
Yukihiro "Matz" Matsumoto e47b4ca704 mruby-string-ext: new method String#force_encoding
It takes a string instead of Encoding object for simplicity
2025-01-12 23:13:28 +09:00
Yukihiro "Matz" Matsumoto d5fa9504ad mruby-string-ext (str_b): String#b should copy the receiver 2025-01-12 23:13:28 +09:00
Yukihiro "Matz" Matsumoto 6c530b8f48 mruby-string-ext (str_append_as_bytes): reimplement in C
To handle strings as byte sequences.
2025-01-12 23:13:27 +09:00
Yukihiro "Matz" Matsumoto 04ab2be2f0 mruby-string-ext (str_ascii_only_p): simplify the flag update 2025-01-03 08:47:38 +09:00
Yukihiro "Matz" Matsumoto 5a7c944a52 mruby-string-ext (str_b): simplify the flag update 2025-01-03 08:46:04 +09:00
Yukihiro "Matz" Matsumoto b0127f0cdd mruby-string-ext (str_b): add a new method String#b
The method makes the receiver binary-mode, but in mruby, which is
virtually no meaning.
2025-01-02 18:45:50 +09:00
Yukihiro "Matz" Matsumoto 85df487e63 mruby-string-ext (append_as_bytes): new method introduced by CRuby 3.4
Since mruby does not have Encoding support, append_as_bytes works
exactly same as String#concat.
2025-01-01 16:05:00 +09:00
Yukihiro "Matz" Matsumoto 45078d9a49 mruby-string-ext: fixed typo (casecmp! -> casecmp?) 2024-07-17 02:25:49 +09:00
Yukihiro "Matz" Matsumoto c32a94d878 mruby-string-ext: use presym for initialization 2024-06-14 01:43:03 +09:00
Yukihiro "Matz" Matsumoto 06480f7147 mruby-string-ext: move local variable declarations 2024-05-08 11:29:20 +09:00
Yukihiro "Matz" Matsumoto 6f0c34e04e mruby-string-ext: implement String#ascii_only? method 2024-01-18 22:53:46 +09:00
Yukihiro "Matz" Matsumoto 57fd0edaa7 mruby.h: rename ASCII flag to SINGLE_BYTE
This flag means all the characters in the string can be represented by a
single byte, i.e., the string does not contain any multi-byte character.
Those characters are likely ASCII characters, but may be a part of broken
UTF-8 sequence, so the term 'ASCII' is not sufficient.
2024-01-18 22:50:39 +09:00
Yukihiro "Matz" Matsumoto 4f8fd23f7a mruby-string-ext (str_uminus): remove wrong document
In mruby, deduplication of strings is not implemented (yet), so we have
to remove the description from `String#-@` document.
2024-01-13 23:00:13 +09:00
Yukihiro "Matz" Matsumoto c53d9a33fc mruby-string-ext (mrb_valid_enc_p): simplify the code
By using `mrb_utf8len` directly. If `len == 1` and `ch >= 0x80`, the
character should be an invalid character.
2024-01-13 22:48:16 +09:00
Yukihiro "Matz" Matsumoto 658d5a51ac mruby-string-ext: add test for String#valid_encoding? 2023-12-07 11:34:10 +09:00
Yukihiro "Matz" Matsumoto eabe2d96e2 mruby-string-ext: add String#valid_encoding? method 2023-12-07 10:58:20 +09:00
Yukihiro "Matz" Matsumoto 7d3679dfc8 mruby-string-ext: refactoring
- raise exception in utf8code
- str_codepoints() use mrb_utf8len_table directly
2023-09-27 18:11:19 +09:00
Yukihiro "Matz" Matsumoto 5705d884ce mruby-string-ext (utf8code): change arguments to point at the end 2023-09-27 18:08:12 +09:00
Yukihiro "Matz" Matsumoto 15bb6a9f9b mruby-string-ext: fix a typo; ref #6016 2023-09-23 11:44:15 +09:00
Yukihiro "Matz" Matsumoto 8a538c40c0 mruby-string-ext: implement core part of codepoints in C; close #6061 2023-09-23 11:36:20 +09:00
Yukihiro "Matz" Matsumoto d4a03be96b mruby-string-ext/string.c (str_casecmp): small refactoring 2023-07-12 09:14:45 +09:00
Yukihiro "Matz" Matsumoto f1a3cfbd3b add a space between if and ( 2023-05-22 11:55:21 +09:00
Yukihiro "Matz" Matsumoto e0194bba67 mruby-string-ext/string.c: remove mrb_ prefix from static functions 2023-04-25 14:25:15 +09:00
Yukihiro "Matz" Matsumoto a21edf75ad Use mrb_get_arg1() instead of mrb_get_args() for single argument 2023-02-21 16:33:15 +09:00