Skip to content

Commit

Permalink
Implement missing fixed string code and update notes
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWyrm committed Aug 5, 2011
1 parent 2cb1857 commit 50a03af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion Paladin/NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ TODO:
New executables to install in /common/bin: luagrep, luare, pobgen, pbuild
Implement support for Prebuild and Postbuild groups
Write a template for a Translator testing framework
Create a lua-based grep so that regular expressions in the find box are compatible with the replacement program (grep's UNIX re vs luare's Lua re)
Issue: Printing output for hg push doesn't happen until after the fact. This is mitigated by
setting the preoutgoing hook in the [hooks] section of .hgrc to echo something.
Need to handle password requests for SCMs -- use the getpass command along with setting SSH_ASKPASS and DISPLAY environment variables
Expand Down
29 changes: 29 additions & 0 deletions luagrep
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@

local results = {}

function CharacterEscape(string, set, escapeChar)
-- This performs the same function as the BString::CharacterEscape
-- function in the Haiku API. This is not a cheap function, so use it
-- sparingly
if (not string or (not set) or (not escapeChar) or
type(string) ~= "string" or type(set) ~= "string" or
type(escapeChar) ~= "string") then
return nil
end

local out = {}
local length = string:len()
for i = 1, length do
local currentChar = string:sub(i,i), 1, plain
if (set:find(currentChar, 1, true)) then
table.insert(out, escapeChar)
table.insert(out, currentChar)
else
table.insert(out, currentChar)
end
end
return table.concat(out)
end


function GrepFile(path, searchString, options)
-- actually searches the file
if (not path) then
Expand Down Expand Up @@ -95,6 +120,10 @@ end

searchPattern = arg[argIndex]

if (optionList.fixed) then
searchPattern = CharacterEscape(searchPattern, "^$()%.[]*+-?", "%")
end

for i = argIndex + 1, #arg do
GrepFile(arg[i], searchPattern, options)
end
Expand Down

0 comments on commit 50a03af

Please sign in to comment.