Module: HeadMusic::Notation::LilyPond::StringText

Defined in:
lib/head_music/notation/lily_pond/string_text.rb

Overview

Escapes text for a double-quoted LilyPond string, and reads it back. LilyPond embeds executable Scheme, so an unescaped quote in a header field could break out of the string into code that runs at compile time; the backslash must double first so it cannot re-open what the quote escape closed.

Class Method Summary collapse

Class Method Details

.escape(text) ⇒ Object



9
10
11
# File 'lib/head_music/notation/lily_pond/string_text.rb', line 9

def self.escape(text)
  text.to_s.gsub("\\", "\\\\\\\\").gsub('"', "\\\"")
end

.unescape(text) ⇒ Object

The inverse of escape: the text a double-quoted string's body denotes.



14
15
16
# File 'lib/head_music/notation/lily_pond/string_text.rb', line 14

def self.unescape(text)
  text.to_s.gsub(/\\(["\\])/, '\1')
end