Example #1
0
bool Lexer::isIdentifierNext (int c)
{
  return c                          &&  // Include null character check.
         c != ':'                   &&  // Used in isPair.
         c != '='                   &&  // Used in isPair.
         ! isWhitespace         (c) &&
         ! isSingleCharOperator (c);
}
Example #2
0
void chomp(char *line)
{
    int len = strlen(line);
    while (isWhitespace(line[len]))
    {   
        line[len--] = '\0';
    }   
}
Example #3
0
static inline unsigned skipWhitespaces(const RenderText& textRenderer, unsigned offset, unsigned length)
{
    for (; offset < length; ++offset) {
        if (!isWhitespace(textRenderer.characterAt(offset)))
            break;
    }
    return offset;
}
Example #4
0
	void parseNumber () {
		skipWhitespace();
		while (!eof() && !isWhitespace() &&
			(isSign() || isDot() || isDigit())) {
			put();
			next();
		}
	}
Example #5
0
bool Lexer::isIdentifierStart (int c)
{
  return c                          &&  // Include null character check.
         ! isWhitespace         (c) &&
         ! isDigit              (c) &&
         ! isSingleCharOperator (c) &&
         ! isPunctuation        (c);
}
Example #6
0
 /// \brief Consume all leading whitespace from \c Code.
 void consumeWhitespace() {
   while (!Code.empty() && isWhitespace(Code[0])) {
     if (Code[0] == '\n') {
       ++Line;
       StartOfLine = Code.drop_front();
     }
     Code = Code.drop_front();
   }
 }
Example #7
0
std::string no_whitespace(const std::string &s)
{
  const int sourcesize = (int)s.size();

  int count = 0, i = 0, j = 0;
  for (i = 0; i < sourcesize; i++)
    if (!isWhitespace(s[i]))
      count++;

  // create result string of correct size
  std::string result(count, ' ');

  for (i = 0, j = 0; i < sourcesize; i++)
    if (!isWhitespace(s[i]))
      result[j++] = s[i];

  return result;
}
Example #8
0
void Lexer::space() {
    while(true) {
        char c = _stream->peek();
        if (c != '\n' && isWhitespace(c))
            _stream->read();
        else
            break;
    }
}
Example #9
0
void PositionedGlyph::draw (const Graphics& g) const
{
    if (! isWhitespace())
    {
        LowLevelGraphicsContext* const context = g.getInternalContext();
        context->setFont (font);
        context->drawGlyph (glyph, AffineTransform::translation (x, y));
    }
}
Value FunId::evaluate() const
{
    Value a = argument(0).evaluate();
    StringBuilder idList; // A whitespace-separated list of IDs

    if (!a.isNodeSet())
        idList.append(a.toString());
    else {
        for (auto& node : a.toNodeSet()) {
            idList.append(stringValue(node.get()));
            idList.append(' ');
        }
    }
    
    TreeScope& contextScope = evaluationContext().node->treeScope();
    NodeSet result;
    HashSet<Node*> resultSet;

    unsigned startPos = 0;
    unsigned length = idList.length();
    while (true) {
        while (startPos < length && isWhitespace(idList[startPos]))
            ++startPos;
        
        if (startPos == length)
            break;

        size_t endPos = startPos;
        while (endPos < length && !isWhitespace(idList[endPos]))
            ++endPos;

        // If there are several nodes with the same id, id() should return the first one.
        // In WebKit, getElementById behaves so, too, although its behavior in this case is formally undefined.
        Node* node = contextScope.getElementById(atomicSubstring(idList, startPos, endPos - startPos));
        if (node && resultSet.add(node).isNewEntry)
            result.append(node);
        
        startPos = endPos;
    }
    
    result.markSorted(false);
    
    return Value(WTFMove(result));
}
Example #11
0
/* Retrieve the next character.  If skipwhite is
   true, whitespace is skipped as well. */
static UChar32 getNextChar(UCHARBUF* buf,
                           UBool skipwhite,
                           struct UString *token,
                           UErrorCode *status) {
    UChar32 c, c2;

    if (U_FAILURE(*status)) {
        return U_EOF;
    }

    for (;;) {
        c = ucbuf_getc(buf,status);

        if (c == U_EOF) {
            return U_EOF;
        }

        if (skipwhite && isWhitespace(c)) {
            continue;
        }

        /* This also handles the get() failing case */
        if (c != SLASH) {
            return c;
        }

        c = ucbuf_getc(buf,status); /* "/c" */

        if (c == U_EOF) {
            return U_EOF;
        }

        switch (c) {
        case SLASH:  /* "//" */
            seekUntilNewline(buf, NULL, status);
            break;

        case ASTERISK:  /* " / * " */
            c2 = ucbuf_getc(buf, status); /* "/ * c" */
            if(c2 == ASTERISK){  /* "/ * *" */
                /* parse multi-line comment and store it in token*/
                seekUntilEndOfComment(buf, token, status);
            } else {
                ucbuf_ungetc(c2, buf); /* c2 is the non-asterisk following "/ *".  Include c2  back in buffer.  */
                seekUntilEndOfComment(buf, NULL, status);
            }
            break;

        default:
            ucbuf_ungetc(c, buf); /* "/c" - put back the c */
            /* If get() failed this is a NOP */
            return SLASH;
        }

    }
}
Example #12
0
// ----------------------------------------------------------------------------
// Tokenizer::tokenizeUnknown
//
// Process the current unknown character
// ----------------------------------------------------------------------------
void Tokenizer::tokenizeUnknown()
{
	// Whitespace
	if (isWhitespace(data_[state_.position]))
	{
		state_.state = TokenizeState::State::Whitespace;
		++state_.position;
		return;
	}

	// Comment
	state_.comment_type = checkCommentBegin();
	if (state_.comment_type > 0)
	{
		state_.state = TokenizeState::State::Comment;
		if (state_.comment_type == Hash || state_.comment_type == Shell)
			++state_.position;
		else
			state_.position += 2;

		return;
	}

	// Special character
	if (isSpecialCharacter(data_[state_.position]))
	{
		// End token
		state_.current_token.line_no = state_.current_line;
		state_.current_token.quoted_string = false;
		state_.current_token.pos_start = state_.position;
		++state_.position;
		state_.done = true;
		return;
	}

	// Quoted string
	if (data_[state_.position] == '\"')
	{
		// Skip "
		++state_.position;

		// Begin token
		state_.current_token.line_no = state_.current_line;
		state_.current_token.quoted_string = true;
		state_.current_token.pos_start = state_.position;
		state_.state = TokenizeState::State::Token;

		return;
	}

	// Token
	state_.current_token.line_no = state_.current_line;
	state_.current_token.quoted_string = false;
	state_.current_token.pos_start = state_.position;
	state_.state = TokenizeState::State::Token;
}
Example #13
0
void trimLeadingWhitespace(std::string &text)
{
  for(size_t s = 0; s < text.size(); s++) {
    if (!isWhitespace(text[s])) {
      if (s)
	text.erase(text.begin()+s-1);
      return;
    }
  }
}
Example #14
0
std::string ltrim(const std::string & str)
{
	const char * p = str.data();
	const char * end = p + str.length();

	while (p < end && isWhitespace(*p))
		++p;

	return std::string(p, size_t(end - p));
}
static void getToken(const char* src, char* dest, int size)
{
	const char* in = src;
	char* out = dest;
	--size;
	while (*in && isWhitespace(*in))
	{
		++in;
	}

	while (*in && !isWhitespace(*in) && size)
	{
		*out = *in;
		++out;
		++in;
		--size;
	}
	*out = '\0';
}
Example #16
0
    bool Tokenizer::canStartToken(char ch)
    {
        string chStr = string(1, ch);
        if (isOperatorSubstring(chStr) || isLetter(ch) || isWhitespace(ch) || (ch == '#'))
        {
            return true;
        }

        return false;
    }
Example #17
0
void Processor::skipWhitespace(std::string* target)
{
	while (!buf.eof() && isWhitespace(buf.peek())) {
		if (target) {
			target += buf.getWithoutPrinting();
		} else {
			buf.get();
		}
	}
}
Example #18
0
std::string rtrim(const std::string & str)
{
	const char * p = str.data();
	const char * end = p + str.length();

	while (end > p && isWhitespace(end[-1]))
		--end;

	return std::string(p, size_t(end - p));
}
Example #19
0
bool isRangeTextAllWhitespace(VisiblePosition startPosition, VisiblePosition endPosition)
{
    while (isWhitespace(startPosition.characterAfter())) {
        startPosition = startPosition.next();

        if (startPosition == endPosition)
            return true;
    }

    return false;
}
Example #20
0
// Lex any amount of whitespace followed by a "word" (any sequence of
// non-whitespace characters) from the start of region [Begin,End).  If no word
// is found before End, return StringRef().  Begin is adjusted to exclude the
// lexed region.
StringRef QueryParser::lexWord() {
  while (true) {
    if (Begin == End)
      return StringRef(Begin, 0);

    if (!isWhitespace(*Begin))
      break;

    ++Begin;
  }

  const char *WordBegin = Begin;

  while (true) {
    ++Begin;

    if (Begin == End || isWhitespace(*Begin))
      return StringRef(WordBegin, Begin - WordBegin);
  }
}
Example #21
0
void Context::skipWhitespace(bool skipNewlines) {
	
	const char * esdat = script->data;
	
	// First ignores spaces & unused chars
	for(; pos != script->size && isWhitespace(esdat[pos]); pos++) {
		if(!skipNewlines && esdat[pos] == '\n') {
			return;
		}
	}
}
Example #22
0
LString LString::trimmed() const {
    LString::ConstIterator start = end();
    for (LString::ConstIterator i = begin(); i != end(); i++) {
        if (!isWhitespace(*i)) {
            start = i;
            break;
        }
    }
    if (start == end()) return *this;

    LString::ConstIterator e = end();
    for (LString::ConstIterator i = end() - 1; i != begin(); --i) {
        if (!isWhitespace(*i)) {
            e = i + 1;
            break;
        }
    }

    return LString(start, e);
}
Example #23
0
VisibleSelection visibleSelectionForClosestActualWordStart(const VisibleSelection& selection)
{
    // VisibleSelection validation has a special case when the caret is at the end of a paragraph where
    // it selects the paragraph marker. As well, if the position is at the end of a word, it will select
    // only the space between words. We want to select an actual word so we move the selection to
    // the start of the leftmost word if the character after the selection point is whitespace.

    if (selection.selectionType() != VisibleSelection::RangeSelection) {
        int leftDistance = 0;
        int rightDistance = 0;

        VisibleSelection leftSelection(previousWordPosition(selection.start()));
        bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter()) && leftSelection.start().containerNode() == selection.start().containerNode();
        if (leftSelectionIsOnWord) {
            VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart());
            leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
        }

        VisibleSelection rightSelection = previousWordPosition(nextWordPosition(selection.start()));
        bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter()) && rightSelection.start().containerNode() == selection.start().containerNode();
        if (rightSelectionIsOnWord) {
            VisibleSelection rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart());
            rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
        }

        // Make sure we found an actual word. If not, return the original selection.
        if (!leftSelectionIsOnWord && !rightSelectionIsOnWord)
            return selection;

        if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance <= rightDistance)) {
            // Left is closer or right is invalid.
            return leftSelection;
        }

        // Right is closer or equal, or left was invalid.
        return rightSelection;
    }

    // No adjustment required.
    return selection;
}
Example #24
0
/**
 * Returns true if the given string has only whitespace characters
 */
bool XMLUtils::isWhitespace(const nsAFlatString& aText)
{
    nsAFlatString::const_char_iterator start, end;
    aText.BeginReading(start);
    aText.EndReading(end);
    for ( ; start != end; ++start) {
        if (!isWhitespace(*start)) {
            return false;
        }
    }
    return true;
}
bool getToken(std::istream &is, std::string &token) {
    eatWhitespace(is);
    token.clear();
    char c;
    while(is.good() && !isWhitespace(is.peek())) {
        c = is.get();
        if (is.good()){
            token += c;
        }
    }
    return token.size() > 0;
}
int INIFile::getNextChar(const unsigned char* line, int startpos) {
	while(line[startpos] != '\0') {
		if((line[startpos] == ';') || (line[startpos] == '#')) {
			// comment
			return -1;
		} else if(!isWhitespace(line[startpos])) {
			return startpos;
		}
		startpos++;
	}
	return -1;
}
Example #27
0
char * trimWhitespace(char const * const data) {
  size_t const len = strlen(data);
  size_t newLen = 0;
  char const *begin = NULL;
  char const *end = NULL;
  char *retval = NULL;
  
  if(len == 0) {
    return NULL;
  }
  
  retval = malloc(len+1);
  if(NULL == retval) {
    return NULL;
  }
  memset(retval, 0, len+1);
                  
  begin = &(data[0]);
  end = &(data[len-1]);
  
  while(isWhitespace(*begin) && begin != end) {
    ++begin;
  }

  if(begin == end) {
    return retval;
  }
  
  while(isWhitespace(*end)) {
    --end;
  }

  /* Add 1 so we get [being, end] inclusive */
  newLen = end - begin + 1;
  
  memcpy(retval, begin, newLen);
  retval[newLen] = '\0';
  
  return retval;
}
Example #28
0
////////////////////////////////////////////////////////////////////////////////
// Lexer::Type::path
//   ( / <non-slash, non-whitespace> )+
bool Lexer::isPath (std::string& token, Lexer::Type& type)
{
  std::size_t marker = _cursor;
  int slashCount = 0;

  while (1)
  {
    if (_text[marker] == '/')
    {
      ++marker;
      ++slashCount;
    }
    else
      break;

    if (_text[marker] &&
        ! isWhitespace (_text[marker]) &&
        _text[marker] != '/')
    {
      utf8_next_char (_text, marker);
      while (_text[marker] &&
             ! isWhitespace (_text[marker]) &&
             _text[marker] != '/')
        utf8_next_char (_text, marker);
    }
    else
      break;
  }

  if (marker > _cursor &&
      slashCount > 3)
  {
    type = Lexer::Type::path;
    token = _text.substr (_cursor, marker - _cursor);
    _cursor = marker;
    return true;
  }

  return false;
}
Example #29
0
bool Lexer::isBoundary(char c) {
    if (c == 0)
        return true;
    if (isWhitespace(c))
        return true;
    if (isStringBoundary(c))
        return true;
    if (isCompoundBoundary(c))
        return true;
    if (isPunctuation(c))
        return true;
    return false;
}
Example #30
0
/**Specific Hexadecimal string parsing function.
 * Processes a file stream as a hexadecimal string and
 * stores the content in a PDFToken.
 */
PDFToken *tokenizeHexString(FILE *file) {
    PDFToken *token;
    char c;
	void *temp;

	if ((token = newPDFToken()) == NULL) {
	    foxLog(FATAL, "%s: Could not allocate space for new token.\n", __func__);
		return NULL;
	}

	token->content = calloc(1, BUF_IDENT_SIZE);
	if (token->content == NULL) {
	    foxLog(FATAL, "%s: Could not malloc buffer for comment.\n", __func__);
	    goto ERROR;
	}

	while ((c = fgetc(file)) != EOF) {
		if (isxdigit(c)) {
            if (token->length % 100 == 0) {
                if ((temp = realloc(token->content, token->length + BUF_IDENT_SIZE)) == NULL) {
                    foxLog(FATAL, "%s: Could not realloc.\n", __func__);
                    goto ERROR;
                }
                token->content = temp;
            }

			*(char *)(token->content + token->length++) = c;
		}
		else if (isWhitespace(c)) {
		}
		else if (c == '>') {
            //backupChar(file);
            goto ACCEPT;
		}
		else {
            foxLog(FATAL, "%s: Invalid character in hex string.\n", __func__);
			goto ERROR;
		}
	}

ERROR:
	if (token->content)
	    free(token->content);
	free(token);

	foxLog(FATAL, "%s: ERROR\n", __func__);

ACCEPT:
	token->type = HEXSTRING;
    return token;
}