Пример #1
0
 void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value) const {
   if (value == 0) {
     output.appendText("null", 4);
   }
   else {
     output.appendChar('\"');
     output.appendText(StringUtils::escapeUnicode(value));
     output.appendChar('\"');
   }
 }
Пример #2
0
//-----------------------------------------------------------------------------
static void testAppendChar()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer s = newStringBuffer(&pool, "A test string");
  s.appendChar(&s, '!');
  assertEquals(string, "A test string!", s.str);
  s.appendChar(&s, '-');
  assertEquals(string, "A test string!-", s.str);

  pool.drain(&pool);
}
Пример #3
0
    void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value, size_t length, bool quote) const {
      if (value == 0) {
        if (quote) {
          output.appendText("null", 4);
        }
      }
      else {
        string v(value, length);

        if (quote) {
          output.appendChar('\"');
          output.appendText(StringUtils::escapeUnicode(v));
          output.appendChar('\"');
        }
        else {
          output.appendText(v);
        }
      }
    }
Пример #4
0
bool Lexer::ReadInclusiveRange(const TCHAR prev, QueryToken* token) {
   int ch = prev;
   StringBuffer range;
   range.appendChar(ch);

   while(!reader->Eos()) {
      ch = reader->GetNext();
	  if ( ch == -1 )
		break;
      range.appendChar(ch);

      if(ch == ']'){
         token->set(range.getBuffer(), QueryToken::RANGEIN);
         return true;
      }
   }
   queryparser->throwParserException(_T("Unterminated inclusive range! %d %d::%d"),' ',
      reader->Column(),reader->Column());
   return false;
}
Пример #5
0
TCHAR* ConstantScoreQuery::toString(const TCHAR* /*field*/) const
{
    StringBuffer buf;
    buf.append(_T("ConstantScore("));
    TCHAR* tmp = filter->toString();
    buf.append(tmp);
    _CLLDELETE(tmp);
    buf.appendBoost(getBoost());
    buf.appendChar(_T(')'));
    return buf.giveBuffer();
}
Пример #6
0
bool Lexer::ReadQuoted(const UChar inCharPrev, QueryToken* outQueryToken)
{
	int ch = inCharPrev;
	StringBuffer quoted;
	quoted.appendChar(ch);

	while (!reader->Eos()) {
		ch = reader->GetNext();
		if (ch == -1)
			break;
		quoted.appendChar(ch);
		if (ch == '"') {
			outQueryToken->set(quoted.getBuffer(), 0, quoted.length(), QueryToken::QUOTED);
			return true;
		}
	}
	gLog.log(eTypLogError, "Err > Lexer: Unterminated string at %d::%d", reader->Column(), reader->Line());

	return false;
}
Пример #7
0
bool Lexer::ReadFullField(const UChar inCharPrev, QueryToken* outQueryToken)
{
	int ch = inCharPrev;
	StringBuffer range;
	range.appendChar(ch);

	while (!reader->Eos()) {
		ch = reader->GetNext();
		if (ch == -1)
			break;
		range.appendChar(ch);
		if (ch == '>') {
			outQueryToken->set(range.getBuffer(), 0, range.length(), QueryToken::FULLFIELD);
			return true;
		}
	}
	gLog.log(eTypLogError, "Err > Lexer: Unterminated exclusive range at %d::%d", reader->Column(), reader->Line());

	return false;
}
Пример #8
0
bool Lexer::ReadQuoted(const TCHAR prev, QueryToken* token) {
   int ch = prev;
   StringBuffer quoted;
   quoted.appendChar(ch);

   while(!reader->Eos()) {
      ch = reader->GetNext();

	  if (ch==-1)
		break;

      quoted.appendChar(ch);

      if(ch == '"'){
         token->set(quoted.getBuffer(), QueryToken::QUOTED);
         return true;
      }
   }
   queryparser->throwParserException(_T("Unterminated string! %d %d::%d"),' ',
      reader->Column(),reader->Column());
   return false;
}
Пример #9
0
//-----------------------------------------------------------------------------
static void testToString()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer sb = newStringBuffer(&pool, "A test strin");
  sb.appendChar(&sb, 'g');
  assertEquals(string, "A test string", sb.str);

  string s = sb.toString(&sb, &pool);
  assertEquals(string, "A test string", s);
  assertEquals(unsigned_int, 13, strlen(s));

  pool.drain(&pool);
}
Пример #10
0
ResultStatus CubeWorker::setCellValue(const string& areaIdentifier, const string& sessionIdentifier, const IdentifiersType& path, double value, SplashMode splashMode, bool addValue)
{
	StringBuffer sb;

	sb.appendText("DOUBLE;");
	sb.appendInteger(dbid);
	sb.appendChar(';');
	sb.appendInteger(cubeid);
	sb.appendChar(';');
	sb.appendText(StringUtils::escapeString(areaIdentifier));
	sb.appendChar(';');
	sb.appendText(StringUtils::escapeString(sessionIdentifier));
	sb.appendChar(';');
	sb.appendText(buildPathString(&path));
	sb.appendChar(';');
	sb.appendDecimal(value);
	sb.appendChar(';');
	sb.appendInteger(PaloJob::splashNumber(splashMode));
	sb.appendChar(';');
	sb.appendInteger((int)addValue);

	// we need to change the job-type
	//    dispatcher->downgradeCurrentJobs();

	// send set-cell-value request to worker
	vector<string> result;

	ResultStatus status = execute(sb.c_str(), result);

	if (status != RESULT_OK) {
		return status;
	}

	if (isErrorStatus(result)) {
		throw WorkerException(result[0].substr(6), true);
	} else if (isExceptionStatus(result)) {
		throw WorkerException(result[0].substr(10), true);
	}

	numFailures = 0;
	return RESULT_OK;
}
Пример #11
0
bool Lexer::ReadTerm(const TCHAR prev, QueryToken* token) {
   int ch = prev;
   bool completed = false;
   int32_t asteriskCount = 0;
   bool hasQuestion = false;

   StringBuffer val;
   TCHAR buf[3]; //used for readescaped

   while(true) {
      switch(ch) {
		  case -1:
			  break;
         case '\\':
         {
            if ( ReadEscape(ch, buf) )
                val.append( buf );
			else
				return false;
         }
         break;

         case LUCENE_WILDCARDTERMENUM_WILDCARD_STRING:
            asteriskCount++;
            val.appendChar(ch);
            break;
         case LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR:
            hasQuestion = true;
            val.appendChar(ch);
            break;
         case '\n':
         case '\t':
         case ' ':
         case '+':
         case '-':
         case '!':
         case '(':
         case ')':
         case ':':
         case '^':
         case '[':
         case ']':
         case '{':
         case '}':
         case '~':
         case '"':
            // create new QueryToken
            reader->UnGet();
            completed = true;
            break;
         default:
            val.appendChar(ch);
            break;
   // end of switch
      }

      if(completed || ch==-1 || reader->Eos() )
         break;
      else
         ch = reader->GetNext();
   }

   // create new QueryToken
   if(hasQuestion)
      token->set(val.getBuffer(), QueryToken::WILDTERM);
   else if(asteriskCount == 1 && val.getBuffer()[val.length() - 1] == '*')
      token->set(val.getBuffer(), QueryToken::PREFIXTERM);
   else if(asteriskCount > 0)
      token->set(val.getBuffer(), QueryToken::WILDTERM);
   else if( _tcsicmp(val.getBuffer(), _T("AND"))==0 || _tcscmp(val.getBuffer(), _T("&&"))==0 )
      token->set(val.getBuffer(), QueryToken::AND_);
   else if( _tcsicmp(val.getBuffer(), _T("OR"))==0 || _tcscmp(val.getBuffer(), _T("||"))==0)
      token->set(val.getBuffer(), QueryToken::OR);
   else if( _tcsicmp(val.getBuffer(), _T("NOT"))==0 )
      token->set(val.getBuffer(), QueryToken::NOT);
   else {
      bool isnum = true;
      int32_t nlen=val.length();
      for (int32_t i=0;i<nlen;++i) {
         TCHAR ch=val.getBuffer()[i];
         if ( _istalpha(ch) ) {
            isnum=false;
            break;
         }
      }

      if ( isnum )
         token->set(val.getBuffer(), QueryToken::NUMBER);
      else
         token->set(val.getBuffer(), QueryToken::TERM);
   }
   return true;
}
Пример #12
0
 void JsonXResultGenerator::generateAtom (StringBuffer& output, uint64_t value) const {
   output.appendChar('U');
   output.appendInteger(value);
   output.appendChar('L');
 }
Пример #13
0
bool Lexer::ReadTerm(const UChar inCharPrev, QueryToken* outQueryToken)
{
	int ch = inCharPrev;
	bool completed = false;
	int32_t asteriskCount = 0;
	bool hasQuestion = false;

	StringBuffer val;
	UChar buf[3]; //used for readescaped

	while (true) {
		switch (ch) {
		case -1:
			break;
		case '\\': {
			if (ReadEscape(ch, buf))
				val.append(buf);
			else
				return false;
		}
		break;

		case LUCENE_WILDCARDTERMENUM_WILDCARD_STRING:
			asteriskCount++;
			val.appendChar(ch);
			break;
		case LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR:
			hasQuestion = true;
			val.appendChar(ch);
			break;
		case '\n':
		case '\t':
		case ' ':
		case '+':
		case '-':
		case '!':
		case '(':
		case ')':
		case ':':
		case '^':
		case '[':
		case ']':
		case '{':
		case '}':
		case '<':
		case '>':
		case '~':
		case '"':
			// create new QueryToken
			reader->UnGet();
			completed = true;
			break;
		default:
			val.appendChar(ch);
			break;
			// end of switch
		}

		if (completed || ch == -1 || reader->Eos())
			break;
		else
			ch = reader->GetNext();
	}

	// Create new QueryToken
	const UChar *uStr = val.getBuffer();
	if (hasQuestion)
		outQueryToken->set(uStr, QueryToken::WILDTERM);
	else if (asteriskCount == 1 && uStr[val.length() - 1] == '*')
		outQueryToken->set(uStr, QueryToken::PREFIXTERM);
	else if (asteriskCount > 0)
		outQueryToken->set(uStr, QueryToken::WILDTERM);
	else if (_tcsicmp(uStr, cStrQueryTokenAnd1) == 0 || _tcscmp(uStr, cStrQueryTokenAnd2) == 0)
		outQueryToken->set(uStr, QueryToken::AND_);
	else if (_tcsicmp(uStr, cStrQueryTokenOr1) == 0 || _tcscmp(uStr, cStrQueryTokenOr2) == 0)
		outQueryToken->set(uStr, QueryToken::OR);
	else if (_tcsicmp(uStr, cStrQueryTokenNot) == 0)
		outQueryToken->set(uStr, QueryToken::NOT);
	else {
		bool isnum = true;
		int32_t nlen = val.length();
		for (int32_t i = 0;i < nlen; ++i) {
			UChar ch = uStr[i];
			if (_istalpha(ch)) {
				isnum = false;
				break;
			}
		}
		if (isnum)
			outQueryToken->set(val.getBuffer(), 0, val.length(), QueryToken::NUMBER);
		else
			outQueryToken->set(val.getBuffer(), 0, val.length(), QueryToken::TERM);
	}

	return true;
}
Пример #14
0
 void JsonResultGenerator::generateAtom (StringBuffer& output, string const& value) const {
   output.appendChar('\"');
   output.appendText(StringUtils::escapeUnicode(value));
   output.appendChar('\"');
 }