Skip to content

Commit

Permalink
cleanup: use native Ruby "gsub" method
Browse files Browse the repository at this point in the history
removed our own implementation

- 3.1.13
  • Loading branch information
lslezak committed Jan 20, 2015
1 parent 4aa2298 commit 4ebd358
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
7 changes: 7 additions & 0 deletions package/yast2-nfs-client.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Jan 20 10:18:58 UTC 2015 - lslezak@suse.cz

- cleanup: use native Ruby "gsub" method, removed our own
implementation
- 3.1.13

-------------------------------------------------------------------
Thu Dec 4 09:50:30 UTC 2014 - jreidinger@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-nfs-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-nfs-client
Version: 3.1.12
Version: 3.1.13
Release: 0
Url: https://github.com/yast/yast-nfs-client

Expand Down
31 changes: 3 additions & 28 deletions src/modules/Nfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ def Export
# @param [String] s a string or nil
# @return escaped string or nil
def EscapeSpaces1(s)
s == nil ?
nil :
Builtins.mergestring(Builtins.splitstring(s, " "), "\\040")
s && s.gsub(" ", "\\\\040")
end

# Escape spaces " " -> "\\040" in all values of all entries
Expand All @@ -282,35 +280,12 @@ def EscapeSpaces(entries)
end }
end

# (like awk gsub, but return the result, not number of replacements)
# replaces from back!
# @param [String] regex regular expression to replace
# @param [String] replacement the replacement string
# @param [String] s where to replace
# @return the changed string
def gsub(regex, replacement, s)
temp = nil
while true
# argh, regexpsub logs an error if it cannot sub
break if !Builtins.regexpmatch(s, Ops.add(Ops.add(".*", regex), ".*"))
temp = Builtins.regexpsub(
s,
Ops.add(Ops.add("(.*)", regex), "(.*)"),
Ops.add(Ops.add("\\1", replacement), "\\2")
)
break if temp == nil
s = temp
end
s
end

# Un-escape spaces "\\040" -> " "
# @param [String] s string or nil
# @return escaped string or nil
def UnescapeSpaces1(s)
# escaped space, \040, is /\\040/
# which is "\\\\040"
s == nil ? nil : gsub("\\\\040", " ", s)
# escaped space, \040 is "\\040"
s && s.gsub("\\040", " ")
end

# Un-escape spaces "\\040" -> " " in all values of all entries
Expand Down

0 comments on commit 4ebd358

Please sign in to comment.