User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 15 Oct 2003, 16:10   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
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.
Structural Integrity is offline   Reply With Quote
Unread 15 Oct 2003, 16:14   #2
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
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
pablissimo is offline   Reply With Quote
Unread 15 Oct 2003, 19:53   #3
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Re: Text parsing with standard C

If your regexp is static, use re2c or flex or something.
__________________
#linux
queball is offline   Reply With Quote
Unread 16 Oct 2003, 09:35   #4
Cyp
∞+♪˛
 
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
Cyp is an unknown quantity at this point
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-->
Cyp is offline   Reply With Quote
Unread 16 Oct 2003, 12:44   #5
W
Gubbish
 
Join Date: Sep 2000
Location: #FoW
Posts: 2,323
W is a jewel in the roughW is a jewel in the roughW is a jewel in the rough
Re: Text parsing with standard C

Quote:
Originally Posted by Cyp
probably
*worship*
__________________
Gubble gubble gubble gubble
W is offline   Reply With Quote
Unread 16 Oct 2003, 15:42   #6
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
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?
Structural Integrity is offline   Reply With Quote
Unread 16 Oct 2003, 17:42   #7
SbOlly
Spelling is for pussies
 
SbOlly's Avatar
 
Join Date: Mar 2003
Location: Actually, where the feck am I........?
Posts: 446
SbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant future
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
SbOlly is offline   Reply With Quote
Unread 17 Oct 2003, 01:02   #8
Cyp
∞+♪˛
 
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
Cyp is an unknown quantity at this point
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-->
Cyp is offline   Reply With Quote
Unread 17 Oct 2003, 01:07   #9
Cyp
∞+♪˛
 
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
Cyp is an unknown quantity at this point
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-->
Cyp is offline   Reply With Quote
Unread 17 Oct 2003, 01:19   #10
SbOlly
Spelling is for pussies
 
SbOlly's Avatar
 
Join Date: Mar 2003
Location: Actually, where the feck am I........?
Posts: 446
SbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant futureSbOlly has a brilliant future
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
SbOlly is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
space frontier, rise of earth flapjack Roleplaying 31 23 Oct 2003 15:33
deleted planets MadeMan Planetarion Discussions 40 31 Mar 2003 07:56
Text browsers. No, seriously. BesigedB Planetarion Discussions 62 21 Feb 2003 20:06
Printing text on to a webpage. clarencetheclockworkcake Programming and Discussion 5 3 Nov 2002 01:59


All times are GMT +1. The time now is 20:40.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018