00001 /* 00002 www.sourceforge.net/projects/tinyxpath 00003 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net) 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to anyone to use this software for any 00010 purpose, including commercial applications, and to alter it and 00011 redistribute it freely, subject to the following restrictions: 00012 00013 1. The origin of this software must not be misrepresented; you must 00014 not claim that you wrote the original software. If you use this 00015 software in a product, an acknowledgment in the product documentation 00016 would be appreciated but is not required. 00017 00018 2. Altered source versions must be plainly marked as such, and 00019 must not be misrepresented as being the original software. 00020 00021 3. This notice may not be removed or altered from any source 00022 distribution. 00023 */ 00024 #ifndef __TINYLEXTOKEN_H 00025 #define __TINYLEXTOKEN_H 00026 00027 #include <stdio.h> 00028 #include <string.h> 00029 00030 #include "lex_util.h" 00031 00032 namespace TinyXPath 00033 { 00034 00038 class lex_token 00039 { 00041 char * cp_value; 00043 lexico l_enum; 00045 lex_token * ltp_next, * ltp_prev; 00046 public : 00048 lex_token (lexico l_in_enum, const _byte_ * bp_in_value, unsigned u_in_size) 00049 { 00050 l_enum = l_in_enum; 00051 cp_value = new char [u_in_size + 1]; 00052 if (u_in_size) 00053 memcpy (cp_value, bp_in_value, u_in_size); 00054 cp_value [u_in_size] = 0; 00055 ltp_next = NULL; 00056 ltp_prev = NULL; 00057 } 00059 void v_set_next (lex_token * ltp_in_next) 00060 { 00061 ltp_next = ltp_in_next; 00062 } 00064 void v_set_prev (lex_token * ltp_in_prev) 00065 { 00066 ltp_prev = ltp_in_prev; 00067 } 00069 ~ lex_token () 00070 { 00071 if (cp_value) 00072 delete [] cp_value; 00073 } 00074 00076 lex_token * ltp_get_next () const 00077 { 00078 return ltp_next; 00079 } 00080 00082 lex_token * ltp_get_prev () const 00083 { 00084 return ltp_prev; 00085 } 00086 00088 lex_token * ltp_get_next (int i_nb) 00089 { 00090 lex_token * ltp_ret; 00091 int i; 00092 00093 ltp_ret = this; 00094 for (i = 0; i < i_nb; i++) 00095 { 00096 if (! ltp_ret) 00097 return NULL; 00098 ltp_ret = ltp_ret -> ltp_get_next (); 00099 if (! ltp_ret || ! ltp_ret -> o_is_valid ()) 00100 return NULL; 00101 } 00102 return ltp_ret; 00103 } 00104 00106 lexico lex_get_value () const 00107 { 00108 return l_enum; 00109 } 00110 00112 void v_set (lexico lex_in, const char * cp_repre) 00113 { 00114 unsigned u_length; 00115 00116 l_enum = lex_in; 00117 delete [] cp_value; 00118 u_length = strlen (cp_repre); 00119 cp_value = new char [u_length + 1]; 00120 strcpy (cp_value, cp_repre); 00121 } 00122 00124 const char * cp_get_literal () 00125 { 00126 return cp_value; 00127 } 00128 00130 bool o_is_valid () const {return (l_enum != lex_null);} 00131 } ; 00132 00133 } 00134 00135 #endif