Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/weechat/rubyext/string.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) from_weechat_config(v)



2
3
4
# File 'lib/weechat/rubyext/string.rb', line 2

def self.from_weechat_config(v)
  v
end

Instance Method Details

- (Boolean) channel?

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

- (Object) escaped_split(split_char, escape_char = "\\")



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

- (String) irc_downcase

Downcase a string (nickname) according to RFC 1459.



146
147
148
# File 'lib/weechat/rubyext/string.rb', line 146

def irc_downcase
  downcase.tr("[]\\~", "{}|^")
end

- (String) irc_downcase!

Same as #irc_downcase, but modifying the string in place.



153
154
155
# File 'lib/weechat/rubyext/string.rb', line 153

def irc_downcase!
  replace(irc_downcase)
end

- (String) irc_upcase

Upcases a string (nickname) according to RFC 1459.



160
161
162
# File 'lib/weechat/rubyext/string.rb', line 160

def irc_upcase
  upcase.tr("{}|^", "[]\\~")
end

- (String) irc_upcase!

Same as #irc_upcase, but modifying the string in place.



167
168
169
# File 'lib/weechat/rubyext/string.rb', line 167

def irc_upcase!
  replace(irc_upcase)
end

- (String) nick

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

- (String) remove_color(replacement = '') 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

- (String) remove_color!(replacement = '') 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

- (Object) shell_split

Author:

  • Loren Segal



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

- (Object) to_weechat_config



6
7
8
# File 'lib/weechat/rubyext/string.rb', line 6

def to_weechat_config
  self
end