Example #1
0
static bool mayReflowContent(StringRef Content) {
  Content = Content.trim(Blanks);
  // Lines starting with '@' commonly have special meaning.
  // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists.
  bool hasSpecialMeaningPrefix = false;
  for (StringRef Prefix :
       {"@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
    if (Content.startswith(Prefix)) {
      hasSpecialMeaningPrefix = true;
      break;
    }
  }

  // Numbered lists may also start with a number followed by '.'
  // To avoid issues if a line starts with a number which is actually the end
  // of a previous line, we only consider numbers with up to 2 digits.
  static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\. ");
  hasSpecialMeaningPrefix =
      hasSpecialMeaningPrefix || kNumberedListRegexp->match(Content);

  // Simple heuristic for what to reflow: content should contain at least two
  // characters and either the first or second character must be
  // non-punctuation.
  return Content.size() >= 2 && !hasSpecialMeaningPrefix &&
         !Content.endswith("\\") &&
         // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
         // true, then the first code point must be 1 byte long.
         (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
}
Example #2
0
bool Lexer::isBoundary (int left, int right)
{
  // EOS
  if (right == '\0')                                 return true;

  // XOR
  if (isAlpha (left)       != isAlpha (right))       return true;
  if (isDigit (left)       != isDigit (right))       return true;
  if (isWhitespace (left)  != isWhitespace (right))  return true;

  // OR
  if (isPunctuation (left) || isPunctuation (right)) return true;

  return false;
}
Example #3
0
bool Lexer::isIdentifierStart (int c)
{
  return c                          &&  // Include null character check.
         ! isWhitespace         (c) &&
         ! isDigit              (c) &&
         ! isSingleCharOperator (c) &&
         ! isPunctuation        (c);
}
Example #4
0
File: text.cpp Project: zergin/task
////////////////////////////////////////////////////////////////////////////////
//          Input: hello, world
// Result for pos: ....y......y
bool isWordEnd (const std::string& input, std::string::size_type pos)
{
    // Short circuit: no input means no word end.
    if (input.length () == 0)
        return false;

    // If pos is the last alphanumeric character of the string.
    if (pos == input.length () - 1 && !isspace (input[pos]) && !isPunctuation (input[pos]))
        return true;

    // If pos is not the last alphanumeric character, but there is a following
    // non-alphanumeric character.
    if (pos < input.length () - 1 && !isspace (input[pos]) && !isPunctuation (input[pos])
            && (isspace (input[pos + 1]) || isPunctuation (input[pos + 1])))
        return true;

    return false;
}
Example #5
0
File: text.cpp Project: zergin/task
////////////////////////////////////////////////////////////////////////////////
//          Input: hello, world
// Result for pos: y......y....
bool isWordStart (const std::string& input, std::string::size_type pos)
{
    // Short circuit: no input means no word start.
    if (input.length () == 0)
        return false;

    // If pos is the first non space/punct character of the string.
    if (pos == 0 && !isspace (input[pos]) && !isPunctuation (input[pos]))
        return true;

    // If pos is not the first alphanumeric character, but there is a preceding
    // space/punct character.
    if (pos > 0 && !isspace (input[pos]) && !isPunctuation (input[pos])
            && (isspace (input[pos - 1]) || isPunctuation (input[pos - 1])))
        return true;

    return false;
}
Example #6
0
static bool mayReflowContent(StringRef Content) {
  Content = Content.trim(Blanks);
  // Lines starting with '@' commonly have special meaning.
  static const SmallVector<StringRef, 4> kSpecialMeaningPrefixes = {
      "@", "TODO", "FIXME", "XXX"};
  bool hasSpecialMeaningPrefix = false;
  for (StringRef Prefix : kSpecialMeaningPrefixes) {
    if (Content.startswith(Prefix)) {
      hasSpecialMeaningPrefix = true;
      break;
    }
  }
  // Simple heuristic for what to reflow: content should contain at least two
  // characters and either the first or second character must be
  // non-punctuation.
  return Content.size() >= 2 && !hasSpecialMeaningPrefix &&
         !Content.endswith("\\") &&
         // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
         // true, then the first code point must be 1 byte long.
         (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
}
Example #7
0
File: text.cpp Project: zergin/task
////////////////////////////////////////////////////////////////////////////////
//          Input: hello, world
// Result for pos: ....y......y
//
//          Input: (one) two
// Result for pos: y..yy...y
bool isTokenEnd (const std::string& input, std::string::size_type pos)
{
    // Delegate.
    if (isWordEnd (input, pos))
        return true;

    // Punctuation divides tokens.
    if (pos < input.length () && isPunctuation (input[pos]))
        return true;

    return false;
}
Example #8
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;
}
	CharWindow( const char* src, std::size_t srcsize, const CharTable* punctuation_char_)
		:m_itr( textwolf::CStringIterator( src, srcsize))
		,m_idx(0)
		,m_wordlen(0)
		,m_pos(0)
		,m_punctuation_char(punctuation_char_)
	{
		std::memset( m_prev_ch, 0, sizeof(m_prev_ch));
		m_prev_ch[ 0] = *m_itr;
		if (!isSpace( m_prev_ch[ 0]) && !isPunctuation( m_prev_ch[ 0]))
		{
			++m_wordlen;
		}
	}
	void skip()
	{
		m_pos = m_itr.getPosition();
		++m_itr;
		++m_idx;
		textwolf::UChar ch = *m_itr;
		m_prev_ch[ m_idx & ((unsigned int)NofPrevChar -1)] = ch;
		if (!isSpace( ch) && !isPunctuation( ch))
		{
			++m_wordlen;
		}
		else
		{
			m_wordlen = 0;
		}
	}
Example #11
0
UIGlyph * PD_UI_DissBattle::findFirstPunctuation(int _startIdx){
	// No autos here, it starts at _startIdx
	for (unsigned int i = _startIdx; i < glyphs.size(); ++i){
		UIGlyph * glyph = glyphs.at(i);
		if(isPunctuation(glyph)){
			float w = glyph->getWidth();
			float h = enemyBubbleText->font->getLineHeight();
			punctuationHighlight->childTransform->scale(w, h, 1.f, false);
			punctuationHighlight->setVisible(true);
			++punctuationCnt;
			++iteration;
			return glyph;
		}
	}
	punctuationHighlight->setVisible(false);
	return nullptr;
}
Example #12
0
void parseIdentifier(struct token_info* info, int* tn, int ln, const char* s, size_t slen, size_t* pos, char* urlMode, struct char_char* p)
{
    size_t start = *pos, len = 0;
    char* ident = NULL;

    while(s[*pos] == '/')
    {
        (*pos)++;
    }

    for(; *pos < slen; (*pos)++)
    {
        if(s[*pos] == '\\')
        {
            (*pos)++;
        }
        else if(isPunctuation(p, s[*pos]))
        {
            break;
        }
    }

    len = *pos-start;
    ident = malloc(sizeof(char)*(len+1));
    if(ident == NULL)
    {
        memoryFailure();
        exit(EXIT_FAILURE);
    }

    memcpy(ident, &s[start], len);
    ident[len]='\0';

    if(casecmp(ident, "url") == 0)
    {
        *urlMode = 1;
    }

    pushToken(info, tn, ln, TOKENTYPE_IDENTIFIER, ident);
    free(ident);

    (*pos)--;
}
Example #13
0
void PD_UI_DissBattle::highlightNextWord(int _startIdx){
	unsigned int length = 0;
	float w = 0;
	highlightedWordStart = nullptr;
	highlightedWordEnd = nullptr;

	for(unsigned long int i = _startIdx; i < glyphs.size(); ++i){
		// Search for start of next word
		if(highlightedWordStart == nullptr){
			if(i == 0 || glyphs.at(i-1)->character == ' '){
				highlightedWordStart = glyphs.at(i);
			}
		}

		// If start of word found, continue until end of word
		if(highlightedWordStart != nullptr){
			w += glyphs.at(i)->getWidth();
			if(!isPunctuation(glyphs.at(i))){
				++length;
			}

			if(i == glyphs.size()-1 || glyphs.at(i+1)->character == ' '){
				float h = enemyBubbleText->font->getLineHeight();
				highlightedWordEnd = glyphs.at(i);
				wordHighlight->childTransform->scale(w, h, 1.f, false);
				wordHighlight->setVisible(true);

				sweet::Event * e = new sweet::Event("wordspoken");
				e->setIntData("length", length);
				eventManager->triggerEvent(e);

				return;
			}
		}
	}
	wordHighlight->setVisible(false);
}
int32_t CBC_PDF417HighLevelEncoder::encodeText(CFX_WideString msg,
                                               int32_t startpos,
                                               int32_t count,
                                               CFX_WideString& sb,
                                               int32_t initialSubmode) {
  CFX_WideString tmp;
  int32_t submode = initialSubmode;
  int32_t idx = 0;
  while (true) {
    FX_WCHAR ch = msg.GetAt(startpos + idx);
    switch (submode) {
      case SUBMODE_ALPHA:
        if (isAlphaUpper(ch)) {
          if (ch == ' ') {
            tmp += (FX_WCHAR)26;
          } else {
            tmp += (FX_WCHAR)(ch - 65);
          }
        } else {
          if (isAlphaLower(ch)) {
            submode = SUBMODE_LOWER;
            tmp += (FX_WCHAR)27;
            continue;
          } else if (isMixed(ch)) {
            submode = SUBMODE_MIXED;
            tmp += (FX_WCHAR)28;
            continue;
          } else {
            tmp += (FX_WCHAR)29;
            tmp += PUNCTUATION[ch];
            break;
          }
        }
        break;
      case SUBMODE_LOWER:
        if (isAlphaLower(ch)) {
          if (ch == ' ') {
            tmp += (FX_WCHAR)26;
          } else {
            tmp += (FX_WCHAR)(ch - 97);
          }
        } else {
          if (isAlphaUpper(ch)) {
            tmp += (FX_WCHAR)27;
            tmp += (FX_WCHAR)(ch - 65);
            break;
          } else if (isMixed(ch)) {
            submode = SUBMODE_MIXED;
            tmp += (FX_WCHAR)28;
            continue;
          } else {
            tmp += (FX_WCHAR)29;
            tmp += PUNCTUATION[ch];
            break;
          }
        }
        break;
      case SUBMODE_MIXED:
        if (isMixed(ch)) {
          tmp += MIXED[ch];
        } else {
          if (isAlphaUpper(ch)) {
            submode = SUBMODE_ALPHA;
            tmp += (FX_WCHAR)28;
            continue;
          } else if (isAlphaLower(ch)) {
            submode = SUBMODE_LOWER;
            tmp += (FX_WCHAR)27;
            continue;
          } else {
            if (startpos + idx + 1 < count) {
              FX_WCHAR next = msg.GetAt(startpos + idx + 1);
              if (isPunctuation(next)) {
                submode = SUBMODE_PUNCTUATION;
                tmp += (FX_WCHAR)25;
                continue;
              }
            }
            tmp += (FX_WCHAR)29;
            tmp += PUNCTUATION[ch];
          }
        }
        break;
      default:
        if (isPunctuation(ch)) {
          tmp += PUNCTUATION[ch];
        } else {
          submode = SUBMODE_ALPHA;
          tmp += (FX_WCHAR)29;
          continue;
        }
    }
    idx++;
    if (idx >= count) {
      break;
    }
  }
  FX_WCHAR h = 0;
  int32_t len = tmp.GetLength();
  for (int32_t i = 0; i < len; i++) {
    bool odd = (i % 2) != 0;
    if (odd) {
      h = (FX_WCHAR)((h * 30) + tmp.GetAt(i));
      sb += h;
    } else {
      h = tmp.GetAt(i);
    }
  }
  if ((len % 2) != 0) {
    sb += (FX_WCHAR)((h * 30) + 29);
  }
  return submode;
}
Example #15
0
void _getTokens(const char* s, struct char_char* p, struct token_info* info)
{
    char urlMode = 0, blockMode = 0;
    int tn = 0, ln = 0;
    size_t pos = 0, slen = strlen(s);

    for(; pos < slen; pos++)
    {
        char c = s[pos];
        char cn = s[pos+1];

        if(c == '/' && cn == '*')
        {
            parseMLComment(info, &tn, ln, s, slen, &pos);
        }
        else if (!urlMode && c == '/' && s[pos+5] == '/' && cn == 'd' && s[pos+2] == 'e' && s[pos+3] == 'e' && s[pos+4] == 'p') {
            pushToken(info, &tn, ln, TOKENTYPE_DEEP, "/deep/");
            pos += 5;
        }
        else if(!urlMode && c == '/' && cn == '/')
        {
            if(blockMode > 0)
            {
                parseIdentifier(info, &tn, ln, s, slen, &pos, &urlMode, p);
            }
            else
            {
                parseSLComment(info, &tn, ln, s, slen, &pos);
            }
        }
        else if(c == '"' || c == '\'')
        {
            parseString(info, &tn, ln, s, slen, &pos, c);
        }
        else if(c == ' ')
        {
            parseSpaces(info, &tn, ln, s, slen, &pos);
        }
        else if(isPunctuation(p, c))
        {
            pushChar(info, &tn, ln, isPunctuation(p, c), c);
            if(c == '\n' || c == '\r')
            {
                ln++;
            }

            if(c == ')')
            {
                urlMode = 0;
            }

            if(c == '{')
            {
                blockMode++;
            }

            if(c == '}')
            {
                blockMode--;
            }
        }
        else if(isDecimalDigit(c))
        {
            parseDecimalNumber(info, &tn, ln, s, slen, &pos);
        }
        else
        {
            parseIdentifier(info, &tn, ln, s, slen, &pos, &urlMode, p);
        }
    }
}