Class: String
Class Method Summary collapse
Instance Method Summary collapse
-
#channel? ⇒ Boolean
Checks if the string represents a valid channel name.
- #escaped_split(split_char, escape_char = "\\") ⇒ Object
-
#nick ⇒ String
Returns the nick part of a banmask.
-
#remove_color(replacement = '') ⇒ String
(also: #remove_colors, #strip_colors)
Removes or replaces all color codes.
-
#remove_color!(replacement = '') ⇒ String
(also: #remove_colors!, #strip_colors!)
Same as #remove_color but changing the string in place.
- #shell_split ⇒ Object
- #to_weechat_config ⇒ Object
Class Method Details
.from_weechat_config(v) ⇒ Object
2 3 4 |
# File 'lib/weechat/rubyext/string.rb', line 2 def self.from_weechat_config(v) v end |
Instance Method Details
#channel? ⇒ Boolean
Checks if the string represents a valid channel name
13 14 15 |
# File 'lib/weechat/rubyext/string.rb', line 13 def channel? Weechat.info_get("irc_is_channel", self) == '1' ? true : false end |
#escaped_split(split_char, escape_char = "\\") ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/weechat/rubyext/string.rb', line 44 def escaped_split(split_char, escape_char = "\\") parts = [] escaping = false cur = "" self.split('').each do |char| if char == escape_char if escaping cur << char escaping = false else escaping = true end elsif char == split_char if !escaping parts << cur cur = "" else cur << char escaping = false end else if escaping cur << escape_char escaping = false end cur << char end end parts << cur if parts.size == 1 && parts[0].empty? [] else parts end end |
#nick ⇒ String
Returns the nick part of a banmask
20 21 22 |
# File 'lib/weechat/rubyext/string.rb', line 20 def nick Weechat.info_get("irc_nick_from_host", self) end |
#remove_color(replacement = '') ⇒ String Also known as: remove_colors, strip_colors
Removes or replaces all color codes
28 29 30 |
# File 'lib/weechat/rubyext/string.rb', line 28 def remove_color(replacement='') Weechat.string_remove_color(self, replacement) end |
#remove_color!(replacement = '') ⇒ String Also known as: remove_colors!, strip_colors!
Same as #remove_color but changing the string in place.
38 39 40 |
# File 'lib/weechat/rubyext/string.rb', line 38 def remove_color!(replacement='') self.replace(remove_color(replacement)) end |
#shell_split ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/weechat/rubyext/string.rb', line 82 def shell_split out = [""] state = :none escape_next = false quote = "" strip.split(//).each do |char| case state when :none, :space case char when /\s/ out << "" unless state == :space state = :space escape_next = false when "\\" if escape_next out.last << char escape_next = false else escape_next = true end when '"', "'" if escape_next out.last << char escape_next = false else state = char quote = "" end else state = :none out.last << char escape_next = false end when '"', "'" case char when '"', "'" if escape_next quote << char escape_next = false elsif char == state out.last << quote state = :none else quote << char end when '\\' if escape_next quote << char escape_next = false else escape_next = true end else quote << char escape_next = false end end end out end |
#to_weechat_config ⇒ Object
6 7 8 |
# File 'lib/weechat/rubyext/string.rb', line 6 def to_weechat_config self end |