]> git.lizzy.rs Git - luairc.git/blobdiff - src/irc/ctcp.lua
doc clarification
[luairc.git] / src / irc / ctcp.lua
index 18661221562667ed0ee931ff074d586cc039f11f..c77cae84ac768f3601f643ddeecd04bf5c7cd265 100644 (file)
@@ -15,9 +15,10 @@ module "irc.ctcp"
 --
 -- Applies low level quoting to a string (escaping characters which are illegal
 -- to appear in an IRC packet).
--- @param str String to quote
+-- @param ... Strings to quote together, space separated
 -- @return Quoted string
-function _low_quote(str)
+function _low_quote(...)
+    local str = table.concat({...}, " ")
     return str:gsub("[%z\n\r\020]", {["\000"] = "\0200",
                                      ["\n"]   = "\020n",
                                      ["\r"]   = "\020r",
@@ -45,9 +46,10 @@ end
 --
 -- Applies CTCP quoting to a block of text which has been identified as CTCP
 -- data (by the calling program).
--- @param str String to apply CTCP quoting to
+-- @param ... Strings to apply CTCP quoting to together, space separated
 -- @return String with CTCP quoting applied
-function _ctcp_quote(str)
+function _ctcp_quote(...)
+    local str = table.concat({...}, " ")
     local ret = str:gsub("[\001\\]", {["\001"] = "\\a",
                                       ["\\"]   = "\\\\"})
     return "\001" .. ret .. "\001"
@@ -71,13 +73,17 @@ end
 -- }}}
 
 -- _ctcp_split {{{
--- TODO: again with this string/table thing... it's ugly!
 --
 -- Splits a low level dequoted string into normal text and unquoted CTCP
 -- messages.
 -- @param str Low level dequoted string
--- @return Array, where string values correspond to plain text, and table
---         values have t[1] as the CTCP message
+-- @return Array of tables, with each entry in the array corresponding to one
+--         part of the split message. These tables will have these fields:
+--         <ul>
+--         <li><i>str:</i>  The text of the split section</li>
+--         <li><i>ctcp:</i> True if the section was a CTCP message, false
+--                          otherwise</li>
+--         </ul>
 function _ctcp_split(str)
     local ret = {}
     local iter = 1
@@ -93,11 +99,11 @@ function _ctcp_split(str)
         end
 
         if plain_string ~= "" then
-            table.insert(ret, plain_string)
+            table.insert(ret, {str = plain_string, ctcp = false})
         end
         if not s then break end
         if ctcp_string ~= "" then
-            table.insert(ret, {_ctcp_dequote(ctcp_string)})
+            table.insert(ret, {str = _ctcp_dequote(ctcp_string), ctcp = true})
         end
 
         iter = e + 1