Sha256: dee72a19c09232bd2c3fef81c9b8811f49fa5ae4cfc64f56ad606c8368a2ee92
Contents?: true
Size: 1.65 KB
Versions: 1
Compression:
Stored size: 1.65 KB
Contents
module Apstrings class Line attr_reader :content attr_accessor :in_comment def initialize(line) @content = line @in_comment = false raise "ERROR : Line does not end with `;`, Line => {#{line}}" unless valid? end def empty_line? /^\s*$/.match(content) || false end def slash_comment? content.strip.start_with?("//") end def whole_comment /((^\/\*(.+)\*\/)|(^\/\/(.+)))/.match(content).to_s end def whole_comment? !(whole_comment.empty?) end def open_comment /^\/\*(.+)$/.match(content).to_s end def open_comment? !(open_comment.empty?) end def close_comment /^(.+)\*\/\s*$/.match(content).to_s end def close_comment? !(close_comment.empty?) end def key_value_pair? #Bugfix: 支持 "Key text \" with \" " = "Value text \" with \" "; 格式 !!(/^\s*"([^"]+)[\S\s]*=/.match(content)) end def cleaned_content content.gsub(/;\s*$/, "") end def valid? if key_value_pair? !!(/;[\s]*$/.match(content)) else true end end def key if key_value_pair? cleaned_content.partition(/"\s*=\s*"/)[0].gsub!(/(^")/, "") end end def value if key_value_pair? # puts cleaned_content.partition(/"\s*=\s*"/)[2] # Bugfix : 去掉引号后、冒号前的多余空格 # "key" = "value" ; cleaned_content.partition(/"\s*=\s*"/)[2].rstrip.gsub!(/(^"|"$)/, "") end end def is_comment? whole_comment? || open_comment? || close_comment? || in_comment || slash_comment? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
apstrings-0.4.1 | lib/apstrings/line.rb |