void onQuotedText(lString8 & token) { //CRLog::trace("state==%d: \"%s\"", _state, token.c_str()); if (_state == 11 || _state == 13) { if (!token.empty()) { _url = LVCombinePaths(_basePath, Utf8ToUnicode(token)); } _state = 2; } else if (_state == 5) { if (!token.empty()) { _face = token; } _state = 2; } token.clear(); }
static lString16 decodeText(lString8 text) { if (text.empty()) return lString16::empty_str; lString8 buf; bool lastControl = false; for (int i=0; i<text.length(); i++) { char ch = buf[i]; if (lastControl) { switch (ch) { case 'r': buf.append(1, '\r'); break; case 'n': buf.append(1, '\n'); break; case 't': buf.append(1, '\t'); break; default: buf.append(1, ch); break; } lastControl = false; continue; } if (ch == '\\') { lastControl = true; continue; } buf.append(1, ch); } return Utf8ToUnicode(buf); }
/// extract @import filename from beginning of CSS bool LVProcessStyleSheetImport( const char * &str, lString8 & import_file ) { const char * p = str; import_file.clear(); skip_spaces( p ); if ( *p !='@' ) return false; p++; if (strncmp(p, "import", 6) != 0) return false; p+=6; skip_spaces( p ); bool in_url = false; char quote_ch = 0; if ( !strncmp(p, "url", 3) ) { p+=3; skip_spaces( p ); if ( *p != '(' ) return false; p++; skip_spaces( p ); in_url = true; } if ( *p == '\'' || *p=='\"' ) quote_ch = *p++; while (*p) { if ( quote_ch && *p==quote_ch ) { p++; break; } if ( !quote_ch ) { if ( in_url && *p==')' ) { break; } if ( *p==' ' || *p=='\t' || *p=='\r' || *p=='\n' ) break; } import_file << *p++; } skip_spaces( p ); if ( in_url ) { if ( *p!=')' ) return false; p++; } if ( import_file.empty() ) return false; str = p; return true; }
void onToken(lString8 & token) { if (token.empty()) return; lString8 t = token; token.clear(); //CRLog::trace("state==%d: %s", _state, t.c_str()); if (t == "@font-face") { if (_state == 0) _state = 1; // right after @font return; } if (_state == 1) _state = 0; if (_state == 2) { if (t == "font-family") _state = 4; else if (t == "font-weight") _state = 6; else if (t == "font-style") _state = 8; else if (t == "src") _state = 10; } else if (_state == 5) { _face = t; _state = 2; } else if (_state == 7) { if (t == "bold") _bold = true; _state = 2; } else if (_state == 9) { if (t == "italic") _italic = true; _state = 2; } else if (_state == 11) { if (t == "url") _state = 12; else _state = 2; } }
/// load stylesheet from file, with processing of import bool LVLoadStylesheetFile( lString16 pathName, lString8 & css ) { LVStreamRef file = LVOpenFileStream( pathName.c_str(), LVOM_READ ); if ( file.isNull() ) return false; lString8 txt = UnicodeToUtf8( LVReadTextFile( file ) ); lString8 txt2; const char * s = txt.c_str(); lString8 import_file; if ( LVProcessStyleSheetImport( s, import_file ) ) { lString16 importFilename = LVMakeRelativeFilename( pathName, Utf8ToUnicode(import_file) ); //lString8 ifn = UnicodeToLocal(importFilename); //const char * ifns = ifn.c_str(); if ( !importFilename.empty() ) { LVStreamRef file2 = LVOpenFileStream( importFilename.c_str(), LVOM_READ ); if ( !file2.isNull() ) txt2 = UnicodeToUtf8( LVReadTextFile( file2 ) ); } } if ( !txt2.empty() ) txt2 << "\r\n"; css = txt2 + s; return !css.empty(); }
bool matchEncoded( const lString8 & prefix ) { if ( prefix.empty() ) return false; return encoded.startsWith( prefix ); }
static void addInfoSection( lString8 & buf, lString8 data, const char * caption ) { if ( !data.empty() ) buf << "<tr><td colspan=\"2\" style=\"font-weight: bold; text-align: center\">" << caption << "</td></tr>" << data; }