summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d388b1d)
raw | patch | inline | side by side (parent: d388b1d)
author | mental <mental@users.sourceforge.net> | |
Sat, 30 Jun 2007 23:40:01 +0000 (23:40 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sat, 30 Jun 2007 23:40:01 +0000 (23:40 +0000) |
sake of backwards-compatibility with older Inkscape version; also,
additional comments
additional comments
src/style.cpp | patch | blob | history |
diff --git a/src/style.cpp b/src/style.cpp
index fbd472129516c0750cb2dab0d664e2ecc62988a2..d7e0186b06ffacbe7eb49d6c3095cbb7989c55d7 100644 (file)
--- a/src/style.cpp
+++ b/src/style.cpp
Glib::ustring t;
bool quote = false;
+ bool last_was_space = false;
for (gchar const *i = val; *i; i++) {
+ bool is_space = ( *i == ' ' );
if (g_ascii_isalnum(*i) || *i=='-' || *i=='_') {
+ // ASCII alphanumeric, - and _ don't require quotes
+ t.push_back(*i);
+ } else if ( is_space && !last_was_space ) {
+ // non-consecutive spaces don't require quotes
t.push_back(*i);
} else if (*i=='\'') {
+ // single quotes require escaping and quotes
t.push_back('\\');
t.push_back(*i);
quote = true;
} else {
+ // everything else requires quotes
t.push_back(*i);
quote = true;
}
if (i == val && !g_ascii_isalpha(*i)) {
+ // a non-ASCII/non-alpha initial character requires quotes
quote = true;
}
+ last_was_space = is_space;
+ }
+
+ if (last_was_space) {
+ // a trailing space requires quotes
+ quote = true;
}
- if (quote) { // we use the ' quotes so the result can go to the XML attribute
+ if (quote) {
+ // we use single quotes so the result can be stored in an XML
+ // attribute without incurring un-aesthetic additional quoting
+ // (our XML emitter always uses double quotes)
t.insert(t.begin(), '\'');
t.push_back('\'');
}