PROFASI
Version 1.5
|
A "chunk" of data in an XML file. More...
#include <prf_xml.hh>
Public Member Functions | |
Chunk () | |
Default constructor. | |
Chunk (const Chunk &) | |
Copy constructor. | |
Chunk (std::string txt, size_t bg, size_t nd) | |
Construct using text and limits. | |
Chunk & | operator= (const Chunk &) |
Assignment operator. | |
size_t | begin () const |
Where it starts. | |
size_t | end () const |
Where it ends. | |
size_t | line_number () const |
A line number, if it was derived from a file. | |
void | line_number (size_t i) |
Assign a line number. | |
chunk_type | type () const |
What kind of chunk it is. | |
bool | is_in (size_t r1, size_t r2) const |
Whether it is within a given scope. | |
void | set_text (std::string s) |
Set the chunk text. | |
void | set_limits (size_t i, size_t j) |
Set the limits. | |
std::string | show () |
The text data of the chunk. | |
std::string | info () |
Info about type, limits and text data. | |
chunk_type | determine_type () |
Determine what kind of a chunk it is. | |
std::string | tag_name () |
Return the tag name (name sans the < > signs) | |
std::map< std::string, std::string > | attribute_list () |
If it is a begin tag, return the specified attributes. | |
A chunk is a string of characters with the following properties:
An XML file is a sequence of chunks. Depending on its content a chunk of data can be classified as an XML begin tag, an end tag, text data, a special tag, or garbage that can not be parsed as proper XML. This class provides ways to handle chunks. It is a helper class for constructing XML node trees out of an XML file.
A Chunk object not only stores the text it represents, it can keep track of its location in the file. For instance, if a chunk <group> appears as characters 123 through 129 in a file, it should be told that its limits are 123 to 130. When XML nodes are constructed from a range of chunks, these limits come in handy. They define the scope of one XML node. Using that scope, it is possible to tell if an XML node is a child of another.
chunk_type Chunk::determine_type | ( | ) |
Determines whether the chunk is an XML begin tag, an end tag, a special tag, data text or garbage. It uses helper functions syntax_check_text() to validate data text, valid_name() to validate the tag name of the chunk or the attributes and syntax_check_attributes() to determine if the attributes have been specified with proper syntax. A valid end tag is of the form </a_valid_name>, where the validity of a_valid_name is determined using the function valid_name(). Spaces between the end of a_valid_name and the closing '>' character are tolerated. A valid begin tag is of the form <a_valid_name valid_attribute_list>.
|
inline |
All chunks are created as type text. This function does not analyze the chunk data to see what type it is. It only reports the stored value for its type. The function determine_type() must be called before using the function type().