mirror of https://github.com/buggins/dlangui.git
CSS parser, initial version
This commit is contained in:
parent
d2d94bfd0b
commit
10602abf3c
|
@ -33,7 +33,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>1</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>1</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -174,7 +174,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>EmbedStandardResources ForceLogs USE_OPENGL</versionids>
|
||||
<versionids>EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -237,7 +237,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>1</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>1</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -276,7 +276,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids> EmbedStandardResources ForceLogs USE_OPENGL</versionids>
|
||||
<versionids>EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -339,7 +339,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>0</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>0</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -480,7 +480,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>EmbedStandardResources ForceLogs USE_OPENGL</versionids>
|
||||
<versionids>EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -543,7 +543,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>1</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>1</useInline>
|
||||
<release>1</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -582,7 +582,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids> EmbedStandardResources ForceLogs USE_OPENGL</versionids>
|
||||
<versionids>EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -645,7 +645,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>1</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>1</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -682,9 +682,9 @@
|
|||
<doXGeneration>1</doXGeneration>
|
||||
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
|
||||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<debugids>DebugRedraw</debugids>
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -747,7 +747,7 @@
|
|||
<useArrayBounds>0</useArrayBounds>
|
||||
<noboundscheck>0</noboundscheck>
|
||||
<useSwitchError>0</useSwitchError>
|
||||
<useUnitTests>1</useUnitTests>
|
||||
<useUnitTests>0</useUnitTests>
|
||||
<useInline>0</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
|
@ -784,9 +784,9 @@
|
|||
<doXGeneration>1</doXGeneration>
|
||||
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
|
||||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<debugids>DebugRedraw</debugids>
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>0</createImplib>
|
||||
|
@ -947,6 +947,10 @@
|
|||
<File path="src\dlangui\graphics\images.d" />
|
||||
<File path="src\dlangui\graphics\resources.d" />
|
||||
</Folder>
|
||||
<Folder name="dom">
|
||||
<File path="src\dlangui\dom\cssparser.d" />
|
||||
<File path="src\dlangui\dom\encoding.d" />
|
||||
</Folder>
|
||||
<Folder name="platforms">
|
||||
<Folder name="common">
|
||||
<File path="src\dlangui\platforms\common\platform.d" />
|
||||
|
|
|
@ -478,7 +478,7 @@
|
|||
<doXGeneration>1</doXGeneration>
|
||||
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
|
||||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<debugids>SDLSettings DebugRedraw</debugids>
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
|
@ -580,7 +580,7 @@
|
|||
<doXGeneration>1</doXGeneration>
|
||||
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
|
||||
<debuglevel>0</debuglevel>
|
||||
<debugids />
|
||||
<debugids>SDLSettings DebugRedraw</debugids>
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>USE_CONSOLE EmbedStandardResources ForceLogs</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,72 @@
|
|||
module dom.encoding;
|
||||
|
||||
string findCharsetDirective(ubyte[] src) {
|
||||
import std.string;
|
||||
import std.algorithm : min;
|
||||
string encoding = null;
|
||||
if (src.length >= 17) {
|
||||
auto head = cast(string)src[0 .. min(1024, src.length)];
|
||||
auto encPos = head.indexOf(`@charset "`);
|
||||
if (encPos >= 0) {
|
||||
head = head[10 .. $];
|
||||
auto endPos = head.indexOf('"');
|
||||
if (endPos > 0) {
|
||||
head = head[0 .. endPos];
|
||||
bool valid = true;
|
||||
ubyte v = 0;
|
||||
foreach(ch; head)
|
||||
v |= ch;
|
||||
if (v & 0x80) {
|
||||
// only code points 0..127
|
||||
// found valid @charset directive
|
||||
return cast(string)head.dup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null; // not found
|
||||
}
|
||||
|
||||
/**
|
||||
Convert CSS code bytes to utf-8.
|
||||
src is source byte stream
|
||||
baseEncoding is name of HTTP stream encoding or base document encoding.
|
||||
*/
|
||||
char[] bytesToUtf8(ubyte[] src, string streamEncoding = null, string environmentEncoding = null) {
|
||||
import std.string;
|
||||
import std.algorithm : min;
|
||||
bool isUtf8 = false;
|
||||
string encoding = null;
|
||||
if (streamEncoding) {
|
||||
encoding = streamEncoding;
|
||||
} else {
|
||||
string charsetDirectiveEncoding = findCharsetDirective(src);
|
||||
if (charsetDirectiveEncoding) {
|
||||
encoding = charsetDirectiveEncoding;
|
||||
if (charsetDirectiveEncoding[0] == 'u' && charsetDirectiveEncoding[1] == 't' && charsetDirectiveEncoding[2] == 'f' && charsetDirectiveEncoding[3] == '-') {
|
||||
isUtf8 = true; // for utf-16be, utf-16le use utf-8
|
||||
encoding = "utf-8";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!encoding && environmentEncoding)
|
||||
encoding = environmentEncoding;
|
||||
if (!encoding) {
|
||||
// check bom
|
||||
// utf-8 BOM
|
||||
if (src.length > 3 && src[0] == 0xEF && src[1] == 0xBB && src[2] == 0xBF) {
|
||||
isUtf8 = true;
|
||||
encoding = "utf-8";
|
||||
src = src[3 .. $];
|
||||
} else {
|
||||
// TODO: support other UTF-8 BOMs
|
||||
}
|
||||
}
|
||||
if (isUtf8) {
|
||||
// no decoding needed
|
||||
return cast(char[])src.dup;
|
||||
}
|
||||
// TODO: support more encodings
|
||||
// unknown encoding
|
||||
return null;
|
||||
}
|
Loading…
Reference in New Issue