1 /* $Id: BSString.cpp,v 5.0 2001/04/07 20:00:59 dik Exp $
2  *
3  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
4  *
5  *      Bj�rn Stabell        <bjoern@xpilot.org>
6  *      Ken Ronny Schouten   <ken@xpilot.org>
7  *      Bert Gijsbers        <bert@xpilot.org>
8  *      Dick Balaska         <dick@xpilot.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 // BSString.cpp - BuckoSoft String Implementation
26 // Copyright � 1995-1997 BuckoSoft, Inc.
27 // This class wraps CString to give us some token parsing abilities
28 
29 #include "stdafx.h"
30 #include "bsstring.h"
31 #include <ctype.h>
32 
33 const char separators[] = " \t\n";
34 
CBSString()35 CBSString::CBSString()
36 {
37 	this->CString::CString();
38 }
39 
CBSString(const char * psz)40 CBSString::CBSString(const char* psz)
41 {
42 	this->CString::CString(psz);
43 }
44 
CBSString(const CBSString & stringSrc)45 CBSString::CBSString(const CBSString& stringSrc)
46 {
47 	this->CString::CString((const CString&)stringSrc);
48 }
49 
CBSString(const CString & stringSrc)50 CBSString::CBSString(const CString& stringSrc)
51 {
52 	this->CString::CString(stringSrc);
53 }
54 
CBSString(const CBSString * cbs)55 CBSString::CBSString(const CBSString* cbs)
56 {
57 	this->CString::CString((const char*)cbs);
58 }
59 
GetToken()60 CBSString CBSString::GetToken()
61 {
62 	CBSString	ct;
63 	ct = SpanIncluding(separators);		// skip white space
64 	if (ct.GetLength())
65 		ct = Mid(ct.GetLength());
66 	else
67 		ct = (const char*)this[0];
68 	ct = ct.SpanExcluding(separators);
69 	return(ct);
70 }
SkipSpace()71 CBSString CBSString::SkipSpace()
72 {
73 	CBSString	ct;
74 	ct = SpanIncluding(separators);		// skip white space
75 	return(Right(GetLength() - ct.GetLength()));
76 
77 }
78 
SkipToken()79 CBSString CBSString::SkipToken()
80 {
81 	CBSString cs, ct;
82 	cs = SkipSpace();
83 	ct = cs.SpanExcluding(separators);
84 	cs = cs.Right(cs.GetLength() - ct.GetLength());
85 	return(cs);
86 }
87 
MatchToken(const char * list[])88 int CBSString::MatchToken(const char *list[])
89 {
90 	int i = 0;
91 	while (*list != NULL)
92 	{
93 //		TRACE("MatchToken: <%s> <%s>\n", *list, (const char*)*this);
94 		if (!strcmp((const char*)*list, (const char*)*this))
95 //		if (this == *list)
96 			return(i);
97 		list++;
98 		i++;
99 	}
100 	return(-1);
101 }
102 
ParseColor()103 COLORREF CBSString::ParseColor()
104 {
105 	CBSString	cs, ct;
106 	int			r,g,b;
107 
108     ct = GetToken();
109     r = atoi(ct);
110     cs = SkipToken();
111     ct = cs.GetToken();
112     g = atoi(ct);
113     cs = cs.SkipToken();
114     ct = cs.GetToken();
115     b = atoi(ct);
116 //    TRACE("ParseColor: r/g/b = %d/%d/%d\n", r, g, b);
117     return(RGB(r,g,b));
118 }
119 
ParsePoint()120 POINT	CBSString::ParsePoint()
121 {
122 	CBSString	cs, ct;
123 
124 	POINT	p;
125 	ct = GetToken();
126 	p.x = atoi(ct);
127 	cs = SkipToken();
128 	ct = cs.GetToken();
129 	p.y = atoi(ct);
130 	return(p);
131 }
132 
ParseRect()133 CRect	CBSString::ParseRect()
134 {
135 	CRect	r;
136 	CBSString	cs, ct;
137 	ct = GetToken();
138 	r.left = atoi(ct);
139 	cs = SkipToken();
140 	ct = cs.GetToken();
141 	r.top = atoi(ct);
142 	cs = cs.SkipToken();
143 	ct = cs.GetToken();
144 	r.right = atoi(ct);
145 	cs = cs.SkipToken();
146 	ct = cs.GetToken();
147 	r.bottom = atoi(ct);
148 	return(r);
149 }
150