Skip to content
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

string.gsub is nice #176

Closed
numToStr opened this issue Jul 7, 2022 · 1 comment
Closed

string.gsub is nice #176

numToStr opened this issue Jul 7, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@numToStr
Copy link
Owner

numToStr commented Jul 7, 2022

Somehow, I forgot about string.gsub which is powerful & useful, and I think using it should reduce the string concatenation mess that I currently have.

-- Uncommenting                                                        
                                                                       
local a = '   /*     /*     .class {}           */           */'       
                                                                       
print(vim.inspect({ string.gsub(a, '^(%s*)/%*%s(.-)%s%*/$', '%1%2') }))
                                                                       
local a1 = '    --     local    a   =    123'                          
                                                                       
print(vim.inspect({ string.gsub(a1, '^(%s*)%-%-%s', '%1') }))          
                                                                       
-- Commenting                                                          
                                                                       
local b = '      .class {}     '                                       
                                                                       
print(vim.inspect({ string.gsub(b, '^(%s*)(.*)', '%1/* %2 */') }))     
                                                                       
local b1 = '     local a = 123'                                        
                                                                       
print(vim.inspect({ string.gsub(b1, '^(%s*)', '%1-- ') }))        

local padding = ' '
local min_indent = 4
local b2 = '        local a = 123'

print(vim.inspect({
    string.gsub(
        b2,
        min_indent and string.format('^(%s)', string.rep('%s', min_indent)) or '^(%s*)',
        string.format('%%1--%s', padding)
    ),
}))
     

(I am also not sure whether this will work for all the cases, well I need to explore that too)

@numToStr numToStr added the enhancement New feature or request label Jul 7, 2022
@numToStr numToStr mentioned this issue Jul 7, 2022
7 tasks
@numToStr
Copy link
Owner Author

Done, wherever necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant