|
15 Oct 2003, 16:10
|
#1
|
Rawr rawr
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
|
Text parsing with standard C
Is there a way of doing some quick text parsing with C? Like regular expressions?
I'd like to have a parser that can parse me some XML-like text for creating menus, but the standard ssprintf function won't let me retrieve things that are between "<" and ">" tags.
I'm not into using a standard XML library as I want to use this for other purposes too.
|
|
|
15 Oct 2003, 16:14
|
#2
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: Text parsing with standard C
http://www.pcre.org/ is home to an open-source RegEx library of the vein that mIRC uses though it's C++ not C.
__________________
You're now playing ketchup
|
|
|
15 Oct 2003, 19:53
|
#3
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Re: Text parsing with standard C
If your regexp is static, use re2c or flex or something.
__________________
#linux
|
|
|
16 Oct 2003, 09:35
|
#4
|
∞+♪˛
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
|
Re: Text parsing with standard C
for(;*o&&60^*o;++o);if(*o){
for(;*++o&&62^*o;*O/*o++);
for(;o*O/0&&61^*/++=*o);
*O=0;}
This probably copies the first instance of text between the characters '<' and '>' from the string o to the string O, if there is a '<' in o. If there isn't, just copies to the end of the string. The string O should be infinitely long, to avoid buffer overruns.
__________________
Structural Integrity for Creator - since he'll probably make PA turn 3D.
Wikipedia forum
Note to self - Don't write Chinese letters with bold and italics... 猫
<!--Last incarnation: Nov 2000-->
|
|
|
16 Oct 2003, 12:44
|
#5
|
Gubbish
Join Date: Sep 2000
Location: #FoW
Posts: 2,323
|
Re: Text parsing with standard C
Quote:
Originally Posted by Cyp
probably
|
*worship*
__________________
Gubble gubble gubble gubble
|
|
|
16 Oct 2003, 15:42
|
#6
|
Rawr rawr
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
|
Re: Text parsing with standard C
Quote:
Originally Posted by Cyp
for(;*o&&60^*o;++o);if(*o){
for(;*++o&&62^*o;*O/*o++);
for(;o*O/0&&61^*/++=*o);
*O=0;}
This probably copies the first instance of text between the characters '<' and '>' from the string o to the string O, if there is a '<' in o. If there isn't, just copies to the end of the string. The string O should be infinitely long, to avoid buffer overruns.
|
Do you actually understand that piece of "code" yourself?
|
|
|
16 Oct 2003, 17:42
|
#7
|
Spelling is for pussies
Join Date: Mar 2003
Location: Actually, where the feck am I........?
Posts: 446
|
Re: Text parsing with standard C
Try this (It may work, I'm nowhere near a compiler to check it out myself)
int Count = 0;
int InternalCount = 0;
char *source = MyXMLCode;
char *target = ThePlaceImPuttingMyMenus;
while(*(source + Count) != '\0') Count++;
while((*(source + InternalCount) != '<') & (InternalCount != Count)) InternalCount++;
InternalCount++;
while((*(source + InternalCount) != '>') & (InternalCount != Count)) *target++ = *(source+InternalCount++);
*target = '\0';
__________________
If God made me in his image, he's one fat ugly biatch.
I always get the soggy biscuit
Veni Vidi Codi
|
|
|
17 Oct 2003, 01:02
|
#8
|
∞+♪˛
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
|
Re: Text parsing with standard C
Quote:
Originally Posted by Structural Integrity
Do you actually understand that piece of "code" yourself?
|
Think so, because I just tested it, and it worked.
__________________
Structural Integrity for Creator - since he'll probably make PA turn 3D.
Wikipedia forum
Note to self - Don't write Chinese letters with bold and italics... 猫
<!--Last incarnation: Nov 2000-->
|
|
|
17 Oct 2003, 01:07
|
#9
|
∞+♪˛
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
|
Re: Text parsing with standard C
Quote:
Originally Posted by SbOlly
Try this (It may work, I'm nowhere near a compiler to check it out myself)
...
InternalCount++;
...
|
I think that would probably jump past the terminating null, if there isn't a '<', by the way.
__________________
Structural Integrity for Creator - since he'll probably make PA turn 3D.
Wikipedia forum
Note to self - Don't write Chinese letters with bold and italics... 猫
<!--Last incarnation: Nov 2000-->
|
|
|
17 Oct 2003, 01:19
|
#10
|
Spelling is for pussies
Join Date: Mar 2003
Location: Actually, where the feck am I........?
Posts: 446
|
Re: Text parsing with standard C
Quote:
Originally Posted by Cyp
I think that would probably jump past the terminating null, if there isn't a '<', by the way.
|
Well I can't do everything for him. Where's his challenge then?
__________________
If God made me in his image, he's one fat ugly biatch.
I always get the soggy biscuit
Veni Vidi Codi
|
|
|
|
All times are GMT +1. The time now is 08:10.
| |