| 1 |
// $Id$ |
| 2 |
|
| 3 |
//============================================================================= |
| 4 |
/** |
| 5 |
* @file b_enumerator.cpp |
| 6 |
* |
| 7 |
* @author Fukasawa Mitsuo |
| 8 |
* |
| 9 |
* |
| 10 |
* Copyright (C) 2004 BEE Co.,Ltd. All rights reserved. |
| 11 |
* |
| 12 |
* This program is free software; you can redistribute it and/or |
| 13 |
* modify it under the terms of the GNU General Public License |
| 14 |
* as published by the Free Software Foundation; either version 2 |
| 15 |
* of the License, or (at your option) any later version. |
| 16 |
* |
| 17 |
* This program is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
* GNU General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU General Public License |
| 23 |
* along with this program; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 |
*/ |
| 26 |
//============================================================================= |
| 27 |
|
| 28 |
#define BEE_BUILD_DLL |
| 29 |
|
| 30 |
#include "b_enumerator.h" |
| 31 |
|
| 32 |
b_enumerator * b_enumerator::parse(const char * name, const char * str) |
| 33 |
{ |
| 34 |
b_enumerator * enum_ptr = new b_enumerator(name); |
| 35 |
char * enumstr = (char *)str; |
| 36 |
string token; |
| 37 |
int num = 0, cur = 0; |
| 38 |
while (*enumstr != '\0') |
| 39 |
{ |
| 40 |
if (isspace(*enumstr)) |
| 41 |
{ |
| 42 |
enumstr++; |
| 43 |
continue; |
| 44 |
} |
| 45 |
if (*enumstr == '=') |
| 46 |
{ |
| 47 |
enumstr++; |
| 48 |
while (*enumstr != '\0' && isspace(*enumstr)) |
| 49 |
enumstr++; |
| 50 |
if (*enumstr == '\0') |
| 51 |
break; |
| 52 |
cur = strtol(enumstr, &enumstr, 0); |
| 53 |
if (cur >= num) |
| 54 |
num = cur; |
| 55 |
} |
| 56 |
else if (*enumstr == ',') |
| 57 |
{ |
| 58 |
enum_ptr->add(token, cur); |
| 59 |
token.clear(); |
| 60 |
num++; |
| 61 |
cur = num; |
| 62 |
enumstr++; |
| 63 |
} |
| 64 |
else |
| 65 |
{ |
| 66 |
token.push_back(*enumstr); |
| 67 |
enumstr++; |
| 68 |
} |
| 69 |
} |
| 70 |
enum_ptr->add(token, cur); |
| 71 |
return enum_ptr; |
| 72 |
} |
| 73 |
|