summaryrefslogtreecommitdiff
path: root/ext/strscan/strscan.c
AgeCommit message (Collapse)Author
2024-02-26[ruby/strscan] Add a method for peeking and reading bytes asAaron Patterson
integers (https://github.com/ruby/strscan/pull/89) This commit adds `scan_byte` and `peek_byte`. `scan_byte` will scan the current byte, return it as an integer, and advance the cursor. `peek_byte` will return the current byte as an integer without advancing the cursor. Currently `StringScanner#get_byte` returns a string, but I want to get the current byte without allocating a string. I think this will help with writing high performance lexers. --------- https://github.com/ruby/strscan/commit/873aba2e5d Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2024-02-08[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/ba338b882c
2024-02-08[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/842845af1f
2024-01-19[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/d6f97ec102
2024-01-14[ruby/strscan] StringScanner#captures: Return nil not "" forNAITOH Jun
unmached capture (https://github.com/ruby/strscan/pull/72) fix https://github.com/ruby/strscan/issues/70 If there is no substring matching the group (s[3]), the behavior is different. If there is no substring matching the group, the corresponding element (s[3]) should be nil. ``` s = StringScanner.new('foobarbaz') #=> #<StringScanner 0/9 @ "fooba..."> s.scan /(foo)(bar)(BAZ)?/ #=> "foobar" s[0] #=> "foobar" s[1] #=> "foo" s[2] #=> "bar" s[3] #=> nil s.captures #=> ["foo", "bar", ""] s.captures.compact #=> ["foo", "bar", ""] ``` ``` s = StringScanner.new('foobarbaz') #=> #<StringScanner 0/9 @ "fooba..."> s.scan /(foo)(bar)(BAZ)?/ #=> "foobar" s[0] #=> "foobar" s[1] #=> "foo" s[2] #=> "bar" s[3] #=> nil s.captures #=> ["foo", "bar", nil] s.captures.compact #=> ["foo", "bar"] ``` https://docs.ruby-lang.org/ja/latest/method/MatchData/i/captures.html ``` /(foo)(bar)(BAZ)?/ =~ "foobarbaz" #=> 0 $~.to_a #=> ["foobar", "foo", "bar", nil] $~.captures #=> ["foo", "bar", nil] $~.captures.compact #=> ["foo", "bar"] ``` * StringScanner#captures is not yet documented. https://docs.ruby-lang.org/ja/latest/class/StringScanner.html https://github.com/ruby/strscan/commit/1fbfdd3c6f
2023-12-25Revert "Rollback to released version numbers of stringio and strscan"Hiroshi SHIBATA
This reverts commit 6a79e53823e328281b9e9eee53cd141af28f8548.
2023-12-16Rollback to released version numbers of stringio and strscanHiroshi SHIBATA
2023-11-08[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/1b3393be05
2023-07-28[ruby/strscan] Fix indentation in strscan.cPeter Zhu
[ci skip]
2023-07-27Add function rb_reg_onig_matchPeter Zhu
rb_reg_onig_match performs preparation, error handling, and cleanup for matching a regex against a string. This reduces repetitive code and removes the need for StringScanner to access internal data of regex. Notes: Merged: https://github.com/ruby/ruby/pull/8123
2023-07-27[ruby/strscan] Sync missed commitPeter Zhu
Syncs commit ruby/strscan@76b377a5d875ec77282d9319d62d8f24fe283b40.
2023-02-21[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/681cde0f27
2023-02-21[ruby/strscan] Mention return value of `rest?` in the docOKURA Masafumi
(https://github.com/ruby/strscan/pull/49) The doc of `rest?` was unclear about return value. This commit adds the return value to the doc.
2022-12-26[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/3ada12613d Notes: Merged: https://github.com/ruby/ruby/pull/7025
2022-12-09Merge strscan-3.0.5Hiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/6890
2021-10-24[ruby/strscan] Bump versionSutou Kouhei
If we use the same version as the default strscan gem in Ruby, "gem install" doesn't extract .gem. It fails "gem install" because "gem install" can't find ext/strscan/ to be built. https://github.com/ruby/strscan/commit/3ceafa6cdc Notes: Merged: https://github.com/ruby/ruby/pull/5011
2021-05-06[ruby/strscan] Replace "iff" with "if and only if" (#18)Gannon McGibbon
iff means if and only if, but readers without that knowledge might assume this to be a spelling mistake. To me, this seems like exclusionary language that is unnecessary. Simply using "if and only if" instead should suffice. https://github.com/ruby/strscan/commit/066451c11e
2021-05-06[ruby/strscan] Fix segmentation fault of `StringScanner#charpos` when ↵Kenichi Kamiya
`String#byteslice` returns non string value [Bug #17756] (#20) https://github.com/ruby/strscan/commit/92961cde2b
2021-02-10Update class documentation for StringScannerJeremy Evans
The [] wasn't being displayed, and try to fix formatting for bol? and << (even if they aren't linked). Fixes [Bug #17620]
2020-12-18[strscan] Fix license comment and filesKenta Murata
https://github.com/ruby/strscan/commit/a999f2c6d1
2020-12-18[strscan] Version 3.0.0Kenta Murata
https://github.com/ruby/strscan/commit/08645e4e77
2020-12-18[strscan] Make strscan Ractor safe (#17)Kenta Murata
* Make strscan Ractor safe * Add test-unit in the development dependencies https://github.com/ruby/strscan/commit/3c93c2bebe
2020-10-02mark regex internal to string scannerAaron Patterson
Notes: Merged: https://github.com/ruby/ruby/pull/3623
2020-09-02Document that StringScanner#matched_size returns size in bytes [ci skip]Jeremy Evans
Fixes [Bug #17139]
2020-08-31[ruby/strscan] Bump versionSutou Kouhei
https://github.com/ruby/strscan/commit/df90d541fa
2020-08-31[ruby/strscan] Replaced examples using $KCODE with encodingsNobuyoshi Nakada
`$KCODE` has been deprecated and not effective since years ago. https://github.com/ruby/strscan/commit/7c4dbd4cb3
2020-04-08Suppress -Wshorten-64-to-32 warningsNobuyoshi Nakada
2019-11-18[ruby/strscan] Remove taint supportJeremy Evans
Ruby 2.7 deprecates taint and it no longer has an effect. The lack of taint support should not cause a problem in previous Ruby versions. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-10-14Fixed overflow at onig_region_setNobuyoshi Nakada
To get rid of a bug of `onig_region_set` which takes `int`s instead of `OnigPosition`s, set elements of `beg` and `end` members directly, for the time being.
2019-10-14Import StringScanner 1.0.3 (#2553)Sutou Kouhei
Notes: Merged-By: kou <kou@clear-code.com>
2018-02-16no ID cache in Init functionsnobu
Init functions are called only once, cache is useless. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-08ext/strscan/strscan.c: [DOC] grammar fixesstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29strscan.c: add MatchData-like methodsnobu
* ext/strscan/strscan.c: added `size`, `captures` and `values_at` to StringScanner, shorthands of accessing the matched data. based on the patch by apeiros (Stefan Rusterholz) at [ruby-core:20412]. [Feature #836] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-21strscan.c: fix segfault in arefnobu
* ext/strscan/strscan.c (strscan_aref): fix segfault after get_byte or getch which do not apply regexp. [ruby-core:82116] [Bug #13759] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-28strscan.c: minlnobu
* ext/strscan/strscan.c (minl): extract to reduce repeated S_LEN. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-28strscan.c: use S_RESTLENnobu
* ext/strscan/strscan.c (strscan_getch, strscan_peek), (strscan_rest_size, inspect2): use S_RESTLEN consistently. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-02* re.c: Introduce RREGEXP_PTR.naruse
patch by dbussink. partially merge https://github.com/ruby/ruby/pull/497 * include/ruby/ruby.h: ditto. * gc.c: ditto. * ext/strscan/strscan.c: ditto. * parse.y: ditto. * string.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09* ext/**/*.c (*_memsize): same as r52986 for extensions.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-16allocate structs with wrappernobu
* parse.y (rb_parser_new, ripper_s_allocate): allocate structs with making new wrapper objects and get rid of potential memory leak. * variable.c (rb_autoload): ditto. * ext/digest/digest.c (rb_digest_base_alloc): ditto. * ext/strscan/strscan.c (strscan_s_allocate): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01re.c: rb_reg_region_copynobu
* re.c (rb_reg_region_copy): new function to try with GC if copy failed and return the error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01strscan.c: fix conditionnobu
* ext/strscan/strscan.c (strscan_init_copy): fix inverted condition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01re.c: check if onig_region_copy failednobu
* re.c (CHECK_REGION_COPIED): onig_region_copy() can fail when memory exhausted but returns nothing, so check by if allocated. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-01use 0 for reservednobu
use 0 for rb_data_type_t::reserved instead of NULL, since its type may be changed in the future and possibly not a pointer type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-30protoize no-arguments functionsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-03strscan.c: encoding in messagesnobu
* ext/strscan/strscan.c (strscan_aref): preserve argument encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-03ext: get rid of inadvertent ID creationnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-25introduce ZALLOC{,_N} to replace ALLOC{,_N}+MEMZERO usenormal
Using calloc where possible reduces code and binary sizes. * include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement (Data_Make_Struct, TypedData_Make_Struct): ZALLOC replaces ALLOC+memset * compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO * cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO * io.c (rb_io_reopen): ditto * iseq.c (prepare_iseq_build): ditto * parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto * re.c (match_alloc): ditto * variable.c (rb_const_set): ditto * ext/socket/raddrinfo.c (get_addrinfo): ditto * ext/strscan/strscan.c (strscan_s_allocate): ditto * gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-11* ext/socket/ifaddr.c (IS_IFADDRS): Unused macro removed.akr
* ext/strscan/strscan.c (BUFSIZE): Ditto. * ext/zlib/zlib.c (OBJ_IS_FREED): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-14strscan.c: fix typonobu
* ext/strscan/strscan.c (inspect1): fix typo, rb_str_cat() instead of rb_str_cat2(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-14strscan.c: make string directlynobu
* ext/strscan/strscan.c (inspect1): extract intermediate string from the buffer directly, like as inspect2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e