bool IC_CmdLineParser::handleChar( wchar_t wc, WideString& cmdName, array<WideString>& args ) { static const wchar_t spaceChar = ( wchar_t )' '; static const wchar_t escapeChar = ( wchar_t )'\\'; static const wchar_t quoteChar = ( wchar_t )'\"'; if ( wc == spaceChar ) { if ( !isQuoted() ) { shoveTmpString( cmdName, args ); } else { tmpString += ( spaceChar ); bShouldAddLast = true; } } else if ( wc == quoteChar ) { if ( isEscaped() ) { tmpString += quoteChar; bShouldAddLast = true; setEscaped( false ); } else if ( isQuoted() ) { shoveTmpString( cmdName, args ); setQuoted( false ); } else { setQuoted( true ); } } else if ( wc == escapeChar ) { if ( isEscaped() ) { tmpString += escapeChar; bShouldAddLast = true; setEscaped( false ); } else { setEscaped( true ); } } else { if ( isEscaped() ) { return false; } tmpString += wc; bShouldAddLast = true; } return true; }
DIGESTMD5Properties DIGESTMD5Properties::parse(const ByteArray& data) { DIGESTMD5Properties result; bool inKey = true; ByteArray currentKey; ByteArray currentValue; for (size_t i = 0; i < data.size(); ++i) { char c = static_cast<char>(data[i]); if (inKey) { if (c == '=') { inKey = false; } else { currentKey.push_back(static_cast<unsigned char>(c)); } } else { if (c == ',' && !insideQuotes(currentValue)) { std::string key = byteArrayToString(currentKey); if (isQuoted(key)) { result.setValue(key, byteArrayToString(stripQuotes(currentValue))); } else { result.setValue(key, byteArrayToString(currentValue)); } inKey = true; currentKey = ByteArray(); currentValue = ByteArray(); } else { currentValue.push_back(static_cast<unsigned char>(c)); } } } if (!currentKey.empty()) { std::string key = byteArrayToString(currentKey); if (isQuoted(key)) { result.setValue(key, byteArrayToString(stripQuotes(currentValue))); } else { result.setValue(key, byteArrayToString(currentValue)); } } return result; }
ByteArray DIGESTMD5Properties::serialize() const { ByteArray result; for(DIGESTMD5PropertiesMap::const_iterator i = properties.begin(); i != properties.end(); ++i) { if (i != properties.begin()) { result.push_back(','); } append(result, createByteArray(i->first)); result.push_back('='); if (isQuoted(i->first)) { append(result, createByteArray("\"")); append(result, i->second); append(result, createByteArray("\"")); } else { append(result, i->second); } } return result; }
wxString Identifier::userString(const wxString& s) { if (s.IsEmpty()) return wxEmptyString; wxString ret(s); if (IdentifierQuotes::get().getQuoteAlways()) { if (IdentifierQuotes::get().getQuoteCharsAreRegular()) return quote(escape(ret)); else return quote(escape(strip(ret))); } else { if (isQuoted(ret)) // pass the quoted text as-it-is return ret; if (IdentifierQuotes::get().getQuoteMixedCase() && hasBothCases(ret)) return quote(escape(ret)); if (Identifier::needsQuoting(ret.Upper())) // special chars return quote(escape(ret)); return ret; } }
wxString& Identifier::strip(wxString& s) { if (isQuoted(s)) s = s.SubString(1, s.Length()-2); return s; }
sExpression *eval(sExpression *exp, sEnvironment *env){ /* ------------------atom-----------------------*/ /* 1, 10, false, null, "abc" */ if(isSelfEval(exp)) { return exp; } /* a symbol */ else if(isVariable(exp, env)) { return lookupVariable(toSymb(exp), env); } /* ------------------list-----------------------*/ /* (quote blur blur) */ else if(isQuoted(exp)) { return textOfQuoted(exp); } /* (set! name value) */ else if(isAssignment(exp)) { return evalAssignment(exp, env); } /* (define name value) */ else if(isDefinition(exp)) { return evalDefine(exp, env); } /* (define-syntax name ...) */ else if(isDefinitionSyntax(exp)) { return evalDefineSyntax(exp, env); } /* (if blur blur blur) */ else if(isIf(exp)) { return evalIf(toList(exp), env); } /* (lambda (args) (body)) */ else if(isLambdaConst(exp)) { sList *body; sList *param = toList( cadr(toList(exp))); sExpression *temp = cdr(toList( cdr(toList(exp)))); if(isList(temp)){ body = toList(temp); }else{ body = toList(cons(temp, &sNull)); } return newLambda(param, body, env); } /* (syntax blur blur) syntax rule */ else if(isSymbol(car(toList(exp))) && isSyntaxRule(eval(car(toList(exp)), env))) { sExpression *exp2 = evalSyntaxRule(toSyntax(eval(car(toList(exp)), env)), exp); return eval(exp2, env); } /* the other list (x . y) */ else if(isApplication(exp)) { if(LAZY_EVAL){ sExpression *proexp = actualValue(operator(toList(exp)), env); if(isLambdaType(proexp) || isPrimitiveProc(proexp)){ sExpression *operand = operands(toList(exp)); return applyLazly(proexp, operand, env); } }else{ sExpression *proexp = eval(operator(toList(exp)), env); if(isLambdaType(proexp) || isPrimitiveProc(proexp)){ sExpression *operand = operands(toList(exp)); sExpression *arguments = listOfValues(operand, env); return apply(proexp, arguments, env); } } } return &sError; }