00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <notify.h>
00020
00021 INLINE void ChanEatFrontWhite(std::string& S) {
00022 size_t i = S.find_first_not_of(" \t\r\f\n");
00023 if ((i != std::string::npos) && (i != 0))
00024 S.erase(0, i);
00025 }
00026
00027 INLINE void ChanCheckScoping(std::string& S) {
00028 if (S[0] != '(') {
00029
00030 nout << "error, '" << S << "' does not start with a (" << endl;
00031 S.erase(0, S.find_first_of("("));
00032 }
00033 }
00034
00035 INLINE void ChanDescope(std::string& S) {
00036 int i = ChanMatchingParen(S);
00037 nassertv(i != -1);
00038 S = S.substr(1, i-2);
00039 ChanEatFrontWhite(S);
00040 }
00041
00042 INLINE std::string ChanReadNextWord(std::string& S) {
00043 int i = S.find_first_of(" \t\r\f\n");
00044 std::string stmp = S.substr(0, i);
00045 S.erase(0, i);
00046 ChanEatFrontWhite(S);
00047 return stmp;
00048 }
00049
00050 INLINE int ChanReadNextInt(std::string& S) {
00051 int i = S.find_first_of(" \t\r\f\n");
00052 std::string stmp = S.substr(0, i);
00053 S.erase(0, i);
00054 ChanEatFrontWhite(S);
00055 istringstream st(stmp.c_str());
00056 st >> i;
00057 return i;
00058 }
00059
00060 INLINE bool ChanReadNextBool(std::string& S) {
00061 int i = S.find_first_of(" \t\r\f\n");
00062 std::string stmp = S.substr(0, i);
00063 S.erase(0, i);
00064 ChanEatFrontWhite(S);
00065 bool ret = false;
00066 if ((stmp.length() != 2) || (stmp[0] != '#')) {
00067
00068 nout << "error, '" << stmp << "' is not either #t or #f" << endl;
00069 ret = false;
00070 }
00071 if (stmp[1] == 't')
00072 ret = true;
00073 else if (stmp[1] != 'f') {
00074
00075 nout << "error, '" << stmp << "' is not either #t or #f" << endl;
00076 ret = false;
00077 }
00078 return ret;
00079 }
00080
00081
00082 INLINE int ChanReadNextIntB(std::string& S) {
00083 int i = S.find_first_of(" \t\r\f\n");
00084 std::string stmp = S.substr(0, i);
00085 S.erase(0, i);
00086 ChanEatFrontWhite(S);
00087 i = -1;
00088 if (stmp[0] == '#')
00089 if ((stmp.length() != 2)||(stmp[1] != 'f')) {
00090
00091 nout << "error, '" << stmp << "' is not allowed, only #f or an int"
00092 << endl;
00093 i = -1;
00094 }
00095 else {
00096 istringstream st(stmp.c_str());
00097 st >> i;
00098 }
00099 return i;
00100 }
00101
00102 INLINE float ChanReadNextFloat(std::string& S) {
00103 int i = S.find_first_of(" \t\r\f\n");
00104 std::string stmp = S.substr(0, i);
00105 S.erase(0, i);
00106 ChanEatFrontWhite(S);
00107 istringstream st(stmp.c_str());
00108 float ret;
00109 st >> ret;
00110 return ret;
00111 }