Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
c375fc31
Commit
c375fc31
authored
Sep 15, 2009
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UniXML: remove repeatable conversions
parent
e2453f84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
33 deletions
+50
-33
UniXML.h
include/UniXML.h
+9
-6
UniXML.cc
src/Various/UniXML.cc
+41
-27
No files found.
include/UniXML.h
View file @
c375fc31
...
@@ -69,21 +69,22 @@ public:
...
@@ -69,21 +69,22 @@ public:
// XML
// XML
static
std
::
string
xml2local
(
const
xmlChar
*
xmlT
ext
);
static
std
::
string
xml2local
(
const
std
::
string
t
ext
);
// XML
// XML
// , .
// , .
static
const
xmlChar
*
local2xml
(
std
::
string
text
);
static
const
xmlChar
*
local2xml
(
std
::
string
text
);
static
std
::
string
local2utf8
(
const
std
::
string
text
);
// XML-
// XML-
void
newDoc
(
const
std
::
string
&
root_node
,
std
::
string
xml_ver
=
"1.0"
);
void
newDoc
(
const
std
::
string
&
root_node
,
std
::
string
xml_ver
=
"1.0"
);
// name node
// name node
static
std
::
string
getProp
(
xmlNode
*
node
,
const
std
::
string
name
);
static
std
::
string
getProp
(
const
xmlNode
*
node
,
const
std
::
string
name
);
static
std
::
string
getPropUtf8
(
xmlNode
*
node
,
const
std
::
string
name
);
static
std
::
string
getPropUtf8
(
const
xmlNode
*
node
,
const
std
::
string
name
);
static
int
getIntProp
(
xmlNode
*
node
,
const
std
::
string
name
);
static
int
getIntProp
(
const
xmlNode
*
node
,
const
std
::
string
name
);
/// if value if not positive ( <= 0 ), returns def
/// if value if not positive ( <= 0 ), returns def
static
int
getPIntProp
(
xmlNode
*
node
,
const
std
::
string
name
,
int
def
);
static
int
getPIntProp
(
const
xmlNode
*
node
,
const
std
::
string
name
,
int
def
);
// name node
// name node
static
void
setProp
(
xmlNode
*
node
,
const
std
::
string
name
,
const
std
::
string
text
);
static
void
setProp
(
xmlNode
*
node
,
const
std
::
string
name
,
const
std
::
string
text
);
...
@@ -109,9 +110,11 @@ public:
...
@@ -109,9 +110,11 @@ public:
// ,
// ,
// ->parent
// ->parent
xmlNode
*
findNode
(
xmlNode
*
node
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
);
xmlNode
*
findNode
(
xmlNode
*
node
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
)
const
;
xmlNode
*
findNodeUtf8
(
xmlNode
*
node
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
)
const
;
xmlNode
*
extFindNode
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
,
bool
top
=
true
);
xmlNode
*
extFindNode
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
,
bool
top
=
true
);
xmlNode
*
extFindNodeUtf8
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
std
::
string
searchnode
,
const
std
::
string
name
=
""
,
bool
top
=
true
);
protected
:
protected
:
...
...
src/Various/UniXML.cc
View file @
c375fc31
...
@@ -115,11 +115,9 @@ void UniXML::close()
...
@@ -115,11 +115,9 @@ void UniXML::close()
// XML
// XML
string
UniXML
::
xml2local
(
const
xmlChar
*
xmlTex
t
)
string
UniXML
::
xml2local
(
const
string
t
)
{
{
const
char
*
text
=
(
const
char
*
)
xmlText
;
const
char
*
text
=
t
.
c_str
();
if
(
text
==
0
)
return
""
;
iconv_t
frt
;
iconv_t
frt
;
frt
=
iconv_open
(
InternalEncoding
.
c_str
(),
xmlEncoding
.
c_str
());
frt
=
iconv_open
(
InternalEncoding
.
c_str
(),
xmlEncoding
.
c_str
());
if
(
frt
==
(
iconv_t
)
-
1
)
if
(
frt
==
(
iconv_t
)
-
1
)
...
@@ -198,25 +196,30 @@ const xmlChar* UniXML::local2xml(string text)
...
@@ -198,25 +196,30 @@ const xmlChar* UniXML::local2xml(string text)
delete
[]
inbuf
;
delete
[]
inbuf
;
return
(
xmlChar
*
)
tmpbuf_l2x
;
return
(
xmlChar
*
)
tmpbuf_l2x
;
}
}
string
UniXML
::
local2utf8
(
const
string
text
)
{
return
string
((
const
char
*
)
local2xml
(
text
));
}
string
UniXML
::
getProp
(
xmlNode
*
node
,
const
string
name
)
string
UniXML
::
getProp
(
const
xmlNode
*
node
,
const
string
name
)
{
{
return
xml2local
(
::
xmlGetProp
(
node
,
(
const
xmlChar
*
)
name
.
c_str
()
));
return
xml2local
(
getPropUtf8
(
node
,
name
));
}
}
string
UniXML
::
getPropUtf8
(
xmlNode
*
node
,
const
string
name
)
string
UniXML
::
getPropUtf8
(
const
xmlNode
*
node
,
const
string
name
)
{
{
return
(
const
char
*
)
::
xmlGetProp
(
node
,
(
const
xmlChar
*
)
name
.
c_str
());
return
(
const
char
*
)
::
xmlGetProp
(
(
xmlNode
*
)
node
,
(
const
xmlChar
*
)
name
.
c_str
());
}
}
int
UniXML
::
getIntProp
(
xmlNode
*
node
,
const
string
name
)
int
UniXML
::
getIntProp
(
const
xmlNode
*
node
,
const
string
name
)
{
{
return
UniSetTypes
::
uni_atoi
(
getPropUtf8
(
node
,
name
));
return
UniSetTypes
::
uni_atoi
(
getPropUtf8
(
node
,
name
));
}
}
int
UniXML
::
getPIntProp
(
xmlNode
*
node
,
const
string
name
,
int
def
)
int
UniXML
::
getPIntProp
(
const
xmlNode
*
node
,
const
string
name
,
int
def
)
{
{
int
i
=
getIntProp
(
node
,
name
);
int
i
=
getIntProp
(
node
,
name
);
if
(
i
<=
0
)
if
(
i
<=
0
)
...
@@ -311,44 +314,48 @@ xmlNode* UniXML::nextNode(xmlNode* n)
...
@@ -311,44 +314,48 @@ xmlNode* UniXML::nextNode(xmlNode* n)
return
n
;
return
n
;
}
}
xmlNode
*
UniXML
::
findNode
(
xmlNode
*
node
,
const
string
searchnode
,
const
string
name
)
xmlNode
*
UniXML
::
findNode
Utf8
(
xmlNode
*
node
,
const
string
searchnode
,
const
string
name
)
const
{
{
xmlNode
*
nodeFound
;
// recur++;
while
(
node
!=
NULL
)
while
(
node
!=
NULL
)
{
{
if
(
searchnode
==
xml2local
(
node
->
name
)
)
if
(
searchnode
==
(
const
char
*
)
node
->
name
)
{
{
if
(
name
==
getProp
(
node
,
"name"
)
)
if
(
name
==
getProp
Utf8
(
node
,
"name"
)
)
return
node
;
return
node
;
if
(
name
.
empty
()
)
// == "")
if
(
name
.
empty
()
)
return
node
;
return
node
;
}
}
if
(
(
nodeFound
=
findNode
(
node
->
children
,
searchnode
,
name
))
!=
0
)
xmlNode
*
nodeFound
=
findNode
(
node
->
children
,
searchnode
,
name
);
if
(
nodeFound
!=
NULL
)
return
nodeFound
;
return
nodeFound
;
node
=
node
->
next
;
node
=
node
->
next
;
}
}
// recur--;
return
NULL
;
return
0
;
}
xmlNode
*
UniXML
::
findNode
(
xmlNode
*
node
,
const
string
searchnode
,
const
string
name
)
const
{
return
findNodeUtf8
(
node
,
local2utf8
(
searchnode
),
local2utf8
(
name
));
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
//width means number of nodes of the same level as node in 1-st parameter (width number includes first node)
//width means number of nodes of the same level as node in 1-st parameter (width number includes first node)
//depth means number of times we can go to the children, if 0 we can't go only to elements of the same level
//depth means number of times we can go to the children, if 0 we can't go only to elements of the same level
xmlNode
*
UniXML
::
extFindNode
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
string
searchnode
,
const
string
name
,
bool
top
)
xmlNode
*
UniXML
::
extFindNode
Utf8
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
string
searchnode
,
const
string
name
,
bool
top
)
{
{
xmlNode
*
nodeFound
;
int
i
=
0
;
int
i
=
0
;
while
(
node
!=
NULL
)
while
(
node
!=
NULL
)
{
{
if
(
top
&&
(
i
>=
width
))
return
0
;
if
(
top
&&
(
i
>=
width
))
return
NULL
;
if
(
searchnode
==
xml2local
(
node
->
name
)
)
if
(
searchnode
==
(
const
char
*
)
node
->
name
)
{
{
if
(
name
==
getProp
(
node
,
"name"
)
)
if
(
name
==
getProp
Utf8
(
node
,
"name"
)
)
return
node
;
return
node
;
if
(
name
.
empty
()
)
if
(
name
.
empty
()
)
...
@@ -356,15 +363,22 @@ xmlNode* UniXML::extFindNode(xmlNode* node, int depth, int width, const string s
...
@@ -356,15 +363,22 @@ xmlNode* UniXML::extFindNode(xmlNode* node, int depth, int width, const string s
}
}
if
(
depth
>
0
)
if
(
depth
>
0
)
{
{
if
(
(
nodeFound
=
extFindNode
(
node
->
children
,
depth
-
1
,
width
,
searchnode
,
name
,
false
))
!=
0
)
xmlNode
*
nodeFound
=
extFindNodeUtf8
(
node
->
children
,
depth
-
1
,
width
,
searchnode
,
name
,
false
);
if
(
nodeFound
!=
NULL
)
return
nodeFound
;
return
nodeFound
;
}
}
i
++
;
i
++
;
node
=
node
->
next
;
node
=
node
->
next
;
}
}
return
0
;
return
NULL
;
}
}
xmlNode
*
UniXML
::
extFindNode
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
string
searchnode
,
const
string
name
,
bool
top
)
{
return
extFindNodeUtf8
(
node
,
depth
,
width
,
local2utf8
(
searchnode
),
local2utf8
(
name
),
top
);
}
bool
UniXML_iterator
::
goNext
()
bool
UniXML_iterator
::
goNext
()
{
{
if
(
!
curNode
)
// || !curNode->next )
if
(
!
curNode
)
// || !curNode->next )
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment