1.1 --- a/api.cpp Fri Jul 22 15:38:06 2005 +0000
1.2 +++ b/api.cpp Sat Jul 23 10:26:29 2005 +0000
1.3 @@ -2,11 +2,22 @@
1.4
1.5 #include <qregexp.h>
1.6
1.7 -void API::parseCommand (const QString &s,QString &command,QString
1.8 -¶m)
1.9 +API::API()
1.10 {
1.11 - param="";
1.12 - command="";
1.13 + initCommand();
1.14 +}
1.15 +
1.16 +void API::initCommand()
1.17 +{
1.18 + com="";
1.19 + paramList.clear();
1.20 + errorString="";
1.21 + noErr=true;
1.22 +}
1.23 +
1.24 +void API::parseCommand (const QString &s)
1.25 +{
1.26 + initCommand();
1.27 QRegExp re;
1.28 int pos;
1.29
1.30 @@ -15,24 +26,95 @@
1.31 re.setMinimal (true);
1.32 pos=re.search (s);
1.33 if (pos>=0)
1.34 - command=re.cap(1);
1.35 + com=re.cap(1);
1.36
1.37 // Get parameters
1.38 re.setPattern ("\\((.*)\\)");
1.39 pos=re.search (s);
1.40 if (pos>=0)
1.41 - param=re.cap (1);
1.42 + {
1.43 + QString s=re.cap(1);
1.44 + paramList=QStringList::split(",",s);
1.45 + }
1.46 }
1.47
1.48 -void API::getString (const QString &s, QString &rs)
1.49 +QString API::command()
1.50 {
1.51 - // return the string in s, this could be also stored in
1.52 + return com;
1.53 +}
1.54 +
1.55 +QStringList API::parameters()
1.56 +{
1.57 + return paramList;
1.58 +}
1.59 +
1.60 +QString API::errorDesc()
1.61 +{
1.62 + return errorString;
1.63 +}
1.64 +
1.65 +bool API::error()
1.66 +{
1.67 + // invert noErr
1.68 + return (noErr) ?false:true;
1.69 +}
1.70 +
1.71 +void API::setError(const QString &e)
1.72 +{
1.73 + noErr=false;
1.74 + errorString=e;
1.75 +}
1.76 +
1.77 +bool API::checkParamCount (const uint &expected)
1.78 +{
1.79 + if (paramList.count()!=expected)
1.80 + {
1.81 + errorString=QString("expected %1 parameters, but got %2").arg(expected).arg(paramList.count());
1.82 + return false;
1.83 + }
1.84 + return true;
1.85 +}
1.86 +
1.87 +bool API::checkParamIsInt(const uint &index)
1.88 +{
1.89 + bool ok;
1.90 + if (index > paramList.count())
1.91 + {
1.92 + errorString =QString("Parameter index %1 is outside of parameter list").arg(index);
1.93 + return false;
1.94 + } else
1.95 + {
1.96 + paramList[index].toInt (&ok, 10);
1.97 + if (!ok)
1.98 + {
1.99 + errorString=QString("Parameter %1 is not an integer").arg(index);
1.100 + return false;
1.101 + }
1.102 + return true;
1.103 + }
1.104 +}
1.105 +
1.106 +int API::parInt (bool &ok,const uint &index)
1.107 +{
1.108 + if (checkParamIsInt (index))
1.109 + {
1.110 + return paramList[index].toInt (&ok, 10);
1.111 + }
1.112 + ok=false;
1.113 + return 0;
1.114 +}
1.115 +
1.116 +QString API::parString (bool &ok,const uint &index)
1.117 +{
1.118 + // return the string at index, this could be also stored in
1.119 // a variable later
1.120 + QString r;
1.121 QRegExp re("\"(.*)\"");
1.122 - int pos=re.search (s);
1.123 + int pos=re.search (paramList[index]);
1.124 if (pos>=0)
1.125 - rs=re.cap (1);
1.126 + r=re.cap (1);
1.127 else
1.128 - rs="";
1.129 -
1.130 -}
1.131 \ No newline at end of file
1.132 + r="";
1.133 + ok=true;
1.134 + return r;
1.135 +}