-
-
Notifications
You must be signed in to change notification settings - Fork 179
Add substitute_with_block method to TextRun, that can take a block wtih access to MatchData with regex capture groups etc #161
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
Conversation
…ih access to MatchData with regex capture groups etc I needed to do a `substitute` where the match arg was a regex, and if it were gsub I'd be using a block to have access to capture groups in $1 $2 $3 etc. Because of the weird way variables $1 $2 $3 are handled in ruby and block scope, I couldn't provide a delegated block to give exactly the same API as ordinary gsub. My original idea was to do that, added on to existing #substitute. But instead, had to provide a new/alternate #substitute_with_block method, with a block that actually gets a MatchData object as arg, and can access whatever it needs from there, including capture groups and match string.
04d7d19 to
1a51b4e
Compare
|
Hm, CI failure is weird and annoying.
Any ideas what would be different on CI? The failed test is NOT my new test, but an existing test... don't understand how this PR could cause it to break... is my new test somehow resulting in deletion of a file? But why wouldn't that reproduce locally? docx/spec/docx/document_spec.rb Lines 515 to 536 in 1a51b4e
Any advice? |
|
The CI failure sometimes happens only on GitHub Actions. I reran the tests, and all of them passed. |
|
thank you! |
I needed to do a
substitutewhere the match arg was a regex, and if it were gsub I'd be using a block to have access to capture groups in $1 $2 $3 etc. Because of the weird way variables $1 $2 $3 are handled in ruby and block scope, I couldn't provide a delegated block to give exactly the same API as ordinary gsub. My original idea was to do that, added on to existing #substitute.But instead, had to provide a new/alternate #substitute_block method, with a block that actually gets a MatchData object as arg, and can access whatever it needs from there, including capture groups and match string.