summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2021-06-26 17:08:15 -0300
committerSoniEx2 <endermoneymod@gmail.com>2021-06-26 17:08:15 -0300
commit7a9a4290248ee9019303e9d866f75e4104fe51da (patch)
treeef6bbaa4acab85e7be58b02937ff209fe4613dd3 /src/lib.rs
parent42e6fa41a8f3903e2b8b05baf212b6d2c405d950 (diff)
Clean up Word/Eol
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs115
1 files changed, 8 insertions, 107 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b64cac4..c8b0d80 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -162,9 +162,11 @@ mod eat;
 mod infoid;
 mod internals;
 mod pluginfo;
+mod word;
 
 pub use eat::*;
 pub use infoid::InfoId;
+pub use word::*;
 
 use pluginfo::PluginInfo;
 
@@ -173,7 +175,6 @@ use std::ffi::{CString, CStr};
 use std::marker::PhantomData;
 use std::mem;
 use std::mem::ManuallyDrop;
-use std::ops;
 use std::panic::catch_unwind;
 use std::ptr;
 use std::rc::Rc;
@@ -235,60 +236,6 @@ pub struct PluginHandle {
     info: PluginInfo,
 }
 
-/// Arguments passed to a hook, until the next argument.
-///
-/// # Examples
-/// 
-/// ```
-/// use hexchat_plugin::{PluginHandle, Word, WordEol, Eat};
-///
-/// fn cmd_foo(ph: &mut PluginHandle, arg: Word, arg_eol: WordEol) -> Eat {
-///     if arg.len() < 3 {
-///         ph.print("Not enough arguments");
-///     } else {
-///         ph.print(&format!("{} {} {}", arg[0], arg[1], arg[2]));
-///     }
-///     hexchat_plugin::EAT_ALL
-/// }
-///
-/// fn on_privmsg(ph: &mut PluginHandle, word: Word, word_eol: WordEol) -> Eat {
-///     if word.len() > 0 && word[0].starts_with('@') {
-///         ph.print("We have message tags!?");
-///     }
-///     hexchat_plugin::EAT_NONE
-/// }
-/// ```
-pub struct Word<'a> {
-    word: Vec<&'a str>
-}
-
-/// Arguments passed to a hook, until the end of the line.
-///
-/// # Examples
-/// 
-/// ```
-/// use hexchat_plugin::{PluginHandle, Word, WordEol, Eat};
-///
-/// fn cmd_foo(ph: &mut PluginHandle, arg: Word, arg_eol: WordEol) -> Eat {
-///     if arg.len() < 3 {
-///         ph.print("Not enough arguments");
-///     } else {
-///         ph.print(&format!("{} {} {}", arg[0], arg[1], arg_eol[2]));
-///     }
-///     hexchat_plugin::EAT_ALL
-/// }
-///
-/// fn on_privmsg(ph: &mut PluginHandle, word: Word, word_eol: WordEol) -> Eat {
-///     if word_eol.len() > 0 && word[0].starts_with('@') {
-///         ph.print("We have message tags!?");
-///     }
-///     hexchat_plugin::EAT_NONE
-/// }
-/// ```
-pub struct WordEol<'a> {
-    word_eol: Vec<&'a str>
-}
-
 /// A safety wrapper to ensure you're working with a valid context.
 ///
 /// This mechanism attempts to reduce the likelihood of segfaults.
@@ -370,7 +317,7 @@ impl Drop for CommandHookHandle {
             let b = ((*self.ph).hexchat_unhook)(self.ph, self.hh) as *mut CommandHookUd;
             // we assume b is not null. this should be safe.
             // just drop it
-            mem::drop(Rc::from_raw(b));
+            drop(Rc::from_raw(b));
         }
     }
 }
@@ -380,7 +327,7 @@ impl Drop for ServerHookHandle {
             let b = ((*self.ph).hexchat_unhook)(self.ph, self.hh) as *mut ServerHookUd;
             // we assume b is not null. this should be safe.
             // just drop it
-            mem::drop(Rc::from_raw(b));
+            drop(Rc::from_raw(b));
         }
     }
 }
@@ -390,7 +337,7 @@ impl Drop for PrintHookHandle {
             let b = ((*self.ph).hexchat_unhook)(self.ph, self.hh) as *mut PrintHookUd;
             // we assume b is not null. this should be safe.
             // just drop it
-            mem::drop(Rc::from_raw(b));
+            drop(Rc::from_raw(b));
         }
     }
 }
@@ -405,54 +352,8 @@ impl Drop for TimerHookHandle {
             let b = ((*self.ph).hexchat_unhook)(self.ph, self.hh) as *mut TimerHookUd;
             // we assume b is not null. this should be safe.
             // just drop it
-            mem::drop(Rc::from_raw(b));
-        }
-    }
-}
-
-impl<'a> Word<'a> {
-    unsafe fn new(word: *const *const libc::c_char) -> Word<'a> {
-        let mut vec = vec![];
-        for i in 1..32 {
-            let w = *word.offset(i);
-            if !w.is_null() {
-                vec.push(CStr::from_ptr(w).to_str().expect("non-utf8 word - broken hexchat"))
-            }
-        }
-        while let Some(&"") = vec.last() {
-            vec.pop();
+            drop(Rc::from_raw(b));
         }
-        Word { word: vec }
-    }
-}
-
-impl<'a> ops::Deref for Word<'a> {
-    type Target = [&'a str];
-    fn deref(&self) -> &[&'a str] {
-        &self.word
-    }
-}
-
-impl<'a> WordEol<'a> {
-    unsafe fn new(word_eol: *const *const libc::c_char) -> WordEol<'a> {
-        let mut vec = vec![];
-        for i in 1..32 {
-            let w = *word_eol.offset(i);
-            if !w.is_null() {
-                vec.push(CStr::from_ptr(w).to_str().expect("non-utf8 word_eol - broken hexchat"))
-            }
-        }
-        while let Some(&"") = vec.last() {
-            vec.pop();
-        }
-        WordEol { word_eol: vec }
-    }
-}
-
-impl<'a> ops::Deref for WordEol<'a> {
-    type Target = [&'a str];
-    fn deref(&self) -> &[&'a str] {
-        &self.word_eol
     }
 }
 
@@ -841,7 +742,7 @@ impl PluginHandle {
                     alive.set(false);
                     // HexChat will automatically free the hook.
                     // we just need to free the userdata.
-                    mem::drop(Rc::from_raw(ud as *const TimerHookUd));
+                    drop(Rc::from_raw(ud as *const TimerHookUd));
                     0
                 },
                 Result::Err(e @ _) => {
@@ -859,7 +760,7 @@ impl PluginHandle {
                     alive.set(false);
                     // HexChat will automatically free the hook.
                     // we just need to free the userdata.
-                    mem::drop(Rc::from_raw(ud as *const TimerHookUd));
+                    drop(Rc::from_raw(ud as *const TimerHookUd));
                     0
                 }
             }