00001 /* 00002 * This source file is part of libRocket, the HTML/CSS Interface Middleware 00003 * 00004 * For the latest information, see http://www.librocket.com 00005 * 00006 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 */ 00027 00028 #ifndef ROCKETCORESTYLESHEETPARSER_H 00029 #define ROCKETCORESTYLESHEETPARSER_H 00030 00031 namespace Rocket { 00032 namespace Core { 00033 00034 class PropertyDictionary; 00035 class Stream; 00036 class StyleSheetNode; 00037 00044 class StyleSheetParser 00045 { 00046 public: 00047 StyleSheetParser(); 00048 ~StyleSheetParser(); 00049 00054 int Parse(StyleSheetNode* node, Stream* stream); 00055 00060 bool ParseProperties(PropertyDictionary& parsed_properties, const String& properties); 00061 00062 private: 00063 // Stream we're parsing from. 00064 Stream* stream; 00065 // Parser memory buffer. 00066 String parse_buffer; 00067 // How far we've read through the buffer. 00068 size_t parse_buffer_pos; 00069 00070 // The name of the file we'r parsing. 00071 String stream_file_name; 00072 // Current line number we're parsing. 00073 size_t line_number; 00074 00075 // Parses properties from the parse buffer into the dictionary 00076 // @param properties The dictionary to store the properties in 00077 bool ReadProperties(PropertyDictionary& properties); 00078 00079 // Import properties into the stylesheet node 00080 // @param node Node to import into 00081 // @param names The names of the nodes 00082 // @param properties The dictionary of properties 00083 // @param rule_specificity The specifity of the rule 00084 bool ImportProperties(StyleSheetNode* node, const String& names, const PropertyDictionary& properties, int rule_specificity); 00085 00086 // Attempts to find one of the given character tokens in the active stream 00087 // If it's found, buffer is filled with all content up until the token 00088 // @param buffer The buffer that receives the content 00089 // @param characters The character tokens to find 00090 // @param remove_token If the token that caused the find to stop should be removed from the stream 00091 bool FindToken(String& buffer, const char* tokens, bool remove_token); 00092 00093 // Attempts to find the next character in the active stream. 00094 // If it's found, buffer is filled with the character 00095 // @param buffer The buffer that receives the character, if read. 00096 bool ReadCharacter(char& buffer); 00097 00098 // Fill the internal parse buffer 00099 bool FillBuffer(); 00100 }; 00101 00102 } 00103 } 00104 00105 #endif