Boolean TEditor::search( const char *findStr, ushort opts )
{
    ushort pos = curPtr;
    ushort i;
    do  {
        if( (opts & efCaseSensitive) != 0 )
            i = scan( &buffer[bufPtr(pos)], bufLen - pos, findStr);
        else
            i = iScan( &buffer[bufPtr(pos)], bufLen - pos, findStr);

        if( i != sfSearchFailed )
            {
            i += pos;
            if( (opts & efWholeWordsOnly) == 0 ||
                !(
                    ( i != 0 && isWordChar(bufChar(i - 1)) != 0 ) ||
                    ( i + strlen(findStr) != bufLen &&
                        isWordChar(bufChar(i + strlen(findStr)))
                    )
                 ))
                {
                lock();
                setSelect(i, i + strlen(findStr), False);
                trackCursor(Boolean(!cursorVisible()));
                unlock();
                return True;
                }
            else
                pos = i + 1;
            }
        } while( i != sfSearchFailed );
    return False;
}
ushort TEditor::nextWord( ushort p )
{
    while( p < bufLen && isWordChar(bufChar(p)) != 0 )
        p = nextChar(p);
    while( p < bufLen && isWordChar(bufChar(p)) == 0 )
        p = nextChar(p);
    return p;
}
ushort TEditor::prevWord( ushort p )
{
    while( p > 0 && isWordChar(bufChar(prevChar(p))) == 0 )
        p = prevChar(p);
    while( p > 0 && isWordChar(bufChar(prevChar(p))) != 0 )
        p = prevChar(p);
    return p;
}
示例#4
0
void Highlighter::highlightTerms(const QString & text) {
	int lastWordBreak = 0;
	int textLength = text.length();
	int b;
	while (lastWordBreak < textLength) {
		for (b = lastWordBreak; b < textLength; b++) {
			if (!isWordChar(text.at(b))) break;
		}
		
		if (b > lastWordBreak) {
			TrieLeaf * leaf = NULL;
			if (m_syntaxer->matches(text.mid(lastWordBreak, b - lastWordBreak), leaf)) {
				SyntaxerTrieLeaf * stl = dynamic_cast<SyntaxerTrieLeaf *>(leaf);
				if (stl != NULL) {
					QString format = Syntaxer::formatFromList(stl->name());
					QTextCharFormat * tcf = m_styleFormats.value(format, NULL);
					if (tcf != NULL) {
						setFormat(lastWordBreak, b - lastWordBreak, *tcf);
					}
				}
			}
		}
		
		lastWordBreak = b + 1;
	}
}
示例#5
0
int SumatraUIAutomationTextRange::FindNextWordEndpoint(int pageno, int idx, bool dontReturnInitial) {
    int textLen;
    const WCHAR* pageText = document->GetDM()->textCache->GetData(pageno, &textLen);

    if (dontReturnInitial) {
        for (; idx < textLen; idx++) {
            if (isWordChar(pageText[idx]))
                break;
        }
    }

    for (; idx < textLen; idx++) {
        if (!isWordChar(pageText[idx]))
            break;
    }
    return idx;
}
示例#6
0
void TextSelection::SelectWordAt(int pageNo, double x, double y) {
    int ix = FindClosestGlyph(pageNo, x, y);
    int textLen;
    const WCHAR* text = textCache->GetData(pageNo, &textLen);

    for (; ix > 0; ix--) {
        if (!isWordChar(text[ix - 1]))
            break;
    }
    StartAt(pageNo, ix);

    for (; ix < textLen; ix++) {
        if (!isWordChar(text[ix]))
            break;
    }
    SelectUpTo(pageNo, ix);
}
示例#7
0
// try to match "findText" from "start" with whitespace tolerance
// (ignore all whitespace except after alphanumeric characters)
int TextSearch::MatchLen(const WCHAR *start) const
{
    const WCHAR *match = findText, *end = start;

    if (matchWordStart && start > pageText && isWordChar(start[-1]) && isWordChar(start[0]))
        return -1;

    if (!match)
        return -1;

    while (*match) {
        if (!*end)
            return -1;
        if (caseSensitive ? *match == *end : CharLower((LPWSTR)LOWORD(*match)) == CharLower((LPWSTR)LOWORD(*end)))
            /* characters are identical */;
        else if (str::IsWs(*match) && str::IsWs(*end))
            /* treat all whitespace as identical */;
        // TODO: Adobe Reader seems to have a more extensive list of
        //       normalizations - is there an easier way?
        else if (*match == '-' && (0x2010 <= *end && *end <= 0x2014))
            /* make HYPHEN-MINUS also match HYPHEN, NON-BREAKING HYPHEN,
               FIGURE DASH, EN DASH and EM DASH (but not the other way around) */;
        else if (*match == '\'' && (0x2018 <= *end && *end <= 0x201b))
            /* make APOSTROPHE also match LEFT/RIGHT SINGLE QUOTATION MARK */;
        else if (*match == '"' && (0x201c <= *end && *end <= 0x201f))
            /* make QUOTATION MARK also match LEFT/RIGHT DOUBLE QUOTATION MARK */;
        else
            return -1;
        match++;
        end++;
        // treat "??" and "? ?" differently, since '?' could have been a word
        // character that's just missing an encoding (and '?' is the replacement
        // character); cf. http://code.google.com/p/sumatrapdf/issues/detail?id=1574
        if (*match && !isnoncjkwordchar(*(match - 1)) && (*(match - 1) != '?' || *match != '?') ||
            str::IsWs(*(match - 1)) && str::IsWs(*(end - 1))) {
            SkipWhitespace(match);
            SkipWhitespace(end);
        }
    }

    if (matchWordEnd && end > pageText && isWordChar(end[-1]) && isWordChar(end[0]))
        return -1;

    return (int)(end - start);
}
void FixedHeightLayoutManager::doubleClickHandler(void)
{
	UInt32 initIndex = _CaretIndex;
	PlainDocumentLeafElementRefPtr theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
	std::string theString = theElement->getText();

	Int32 BeginWord = 0;
	Int32 EndWord = theElement->getTextLength();

	if(isPunctuationChar(theString[_CaretIndex]))
	{
		EndWord = _CaretIndex + 1;
		BeginWord = _CaretIndex;
	}
	else
	{
		for(Int32 i = _CaretIndex; i < theElement->getTextLength(); i++)
		{
			if(!isWordChar(theString[i]))
			{
				EndWord = i;
				break;
			}
		}
		for(Int32 i = _CaretIndex; i >= 0; i--)
		{
			if(!isWordChar(theString[i]))
			{
				BeginWord = i + 1;
				break;
			}
		}
	}

	HEL = HSL = _CaretLine;
	HSI = BeginWord;
	HEI = EndWord;

	_CaretIndex = EndWord;

	recalculateCaretPositions();

	getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ (EndWord - initIndex));

}
static int16_t
skipNoise(const char *line, int16_t start, int16_t limit) {
    /* skip anything that is not part of a word in this sense */
    while(start<limit && !isWordChar(line[start])) {
        ++start;
    }

    return start;
}
示例#10
0
int SumatraUIAutomationTextRange::FindPreviousWordEndpoint(int pageno, int idx, bool dontReturnInitial) {
    // based on TextSelection::SelectWordAt
    int textLen;
    const WCHAR* pageText = document->GetDM()->textCache->GetData(pageno, &textLen);

    if (dontReturnInitial) {
        for (; idx > 0; idx--) {
            if (isWordChar(pageText[idx - 1]))
                break;
        }
    }

    for (; idx > 0; idx--) {
        if (!isWordChar(pageText[idx - 1]))
            break;
    }
    return idx;
}
示例#11
0
bool SmartHighlighter::isQualifiedWord(const char *str) const
{
	for (size_t i = 0 ; i < strlen(str) ; i++)
	{
		if (!isWordChar(str[i]))
			return false;
	}
	return true;
};
bool SmartHighlighter::isQualifiedWord(const char *str, char *listChar) const
{
	for (size_t i = 0, len = strlen(str) ; i < len ; ++i)
	{
		if (!isWordChar(str[i], listChar))
			return false;
	}
	return true;
};
示例#13
0
static void
finishAlphanumericWordToken(Tokenizer * const tokP) {

    ++tokP->end;

    while (isWordChar(*tokP->end))
        ++tokP->end;

    tokP->size = tokP->end - tokP->begin;
}
示例#14
0
TCHAR * AutoReplaceMap::filterText(const TCHAR *find)
{
	TCHAR *ret = _tcsdup(find);
	int len = lstrlen(ret);
	int pos = 0;
	for(int i = 0; i < len; i++)
		if (isWordChar(find[i]))
			ret[pos++] = ret[i];
	ret[pos] = 0;
	return CharLower(ret);
}
示例#15
0
static bool_t findNextWordInRawDict(char * rawDict, char ** next, uint_t * nextLen) {
	uint_t i = 0;

	/* Skip any loose terminators in the string's beginning */
	while (('\0' != *rawDict) && !isWordChar(*rawDict)) {
		++rawDict;
	}

	/* If the end of the raw dictionary is reached before any word is found, return FALSE */
	if ('\0' == *rawDict) {
		return FALSE;
	}

	/* Scan the string, looking for the word's ending. */
	for (i = 0; isWordChar(rawDict[i]); ++i) {
		/* Do nothing here */
	}

	*next = rawDict;
	*nextLen = i;

	return TRUE;
}
示例#16
0
文件: path.c 项目: caot/ogdl-c
char * Path_element (char * path, char * buf)
{
    char c;

    if (!*path)
        return 0;

    switch (c=*path)
    {
        case '.':
            *buf++ = *path++;
            break;

        case '[' :

            while ((c=*path) && c != ']' )
                *buf++ = *path++;
            path++;
            break;

        case '{':

            while ((c=*path) && c != '}' )
                *buf++ = *path++;
            path++;
            break;
            
        case '\'':
            while ((c=*path) && c != '\'' )
                *buf++ = *path++;
            path++;
            break;
        
        case '"':
            while ((c=*path) && c != '"' )
                *buf++ = *path++;
            path++;
            break;
        
        default:

            while ((c=*path) && isWordChar(c) )
                *buf++ = *path++;

    }
    
    *buf = 0;
        
    return path;
}
示例#17
0
static int16_t
getWord(const char *line, int16_t start, int16_t limit) {
    char c=0; /* initialize to avoid a compiler warning although the code was safe */

    /* a unicode character name word consists of A-Z0-9 */
    while(start<limit && isWordChar(line[start])) {
        ++start;
    }

    /* include a following space or dash */
    if(start<limit && ((c=line[start])==' ' || c=='-')) {
        ++start;
    }

    return start;
}
示例#18
0
文件: vim.c 项目: Monits/ctags
/* checks if a word at the start of `p` matches at least `min_len` first
 * characters from `word` */
static boolean wordMatchLen(const unsigned char *p, const char *const word, size_t min_len)
{
	const unsigned char *w = (const unsigned char *) word;
	size_t n = 0;

	while (*p && *p == *w)
	{
		p++;
		w++;
		n++;
	}

	if (isWordChar (*p))
		return FALSE;

	return n >= min_len;
}
示例#19
0
bool isCharValid(char currChar)
{
    if(isWordChar(currChar))
        return true;
    switch (currChar) {
    case '#':
    case ';':
    case ' ':
    case '\t':
    case '\n':
    case '|':
    case '&':
    case '(':
    case ')':
    case '<':
    case '>':
        return true;
    }
    return false;
}
示例#20
0
command_stream_t
make_command_stream (int (*get_next_byte) (void *), void *get_next_byte_argument)
{
  //=========Let's just try to read the input in first.============//
  
  size_t bufferSize = 1024;
  size_t bufferIterator = 0;
  char value;
  char* buffer = (char*) checked_malloc(bufferSize);

  while ((value = get_next_byte(get_next_byte_argument)) != EOF) //store into value while it isn't EOF
  {
    buffer[bufferIterator++] = value;
    //    printf("looped once: %c \n", value);
    //    printf("bufferSize: %d \n", (int) bufferSize);
    if (bufferSize == bufferIterator){
      buffer =  (char*) checked_grow_alloc(buffer, &bufferSize);
      //printf("called checked_realloc: %d\n", (int) bufferSize);
    }
  }
  if (bufferSize == bufferIterator){
    buffer =  (char*) checked_grow_alloc(buffer, &bufferSize);
    //printf("called checked_realloc: %d\n", (int) bufferSize);
  }
  buffer[bufferIterator] = '\0';

  //printf("bufferIterator: %d \n", (int) bufferIterator);
  //puts(buffer);  //will output to stdout
  
  //=========Let's tokenize the stream============//
  //we need to do the same thing as before, except instead of taking from the filestream and putting it into the array.
  //Now take the array and put it into a token stream.
  //Could never get the outside function working due to all that referential bullshit.  Let's just do it inline.

  
  token_stream* tstream = (token_stream*) checked_malloc(sizeof(token_stream*));
  token_stream* trackend = tstream;
  int bufferIteratorT = 0;
  int comment = 0;
  int linNumber = 1;

  token_type type;
  
  //do a dual parsing here where we handle two characters at the same time. This makes the && and || and comments easy
  //Need to check if the buffer is completely empty (has '\0' as the only character).  Then we don't do anything so we  //can just return

  if (buffer[bufferIteratorT] == '\0')
  {  
    command_stream_t empty = (command_stream_t) checked_malloc(sizeof(command_stream_t));
    empty->size = 0;
    return empty;
  }
  
  char first;
  char second;
  while (buffer[bufferIteratorT+1] != '\0')
  {
    first = buffer[bufferIteratorT];
    second = buffer[bufferIteratorT+1];

    //Check for &&
    if (first == '&')
      {
        if (second == '&')
          { 
     	    type = AND_TOKEN;
	    bufferIteratorT++;//deals with the fact that && is two chars
          }
        else
          {
	    type = MISC_TOKEN;  //We can test for MISC_TOKEN later, this is an invalid input, only 1 &
          }
      }
    
    //Check for ||
    else if (first == '|')
      {
	if (second == '|')
	  {
	    type = OR_TOKEN;
	    bufferIteratorT++;
          }
	else
	  {
	    type = PIPE_TOKEN;	    
	  }
      }

    else if (first == '#')
      {
	
	if (bufferIteratorT != 0 && isWordChar(buffer[bufferIteratorT-1]))
	  {
	    //if BIT is not 0 , then check if prior is a word, definitely a comment
	    fprintf(stderr,"%i: problem at this line in script\n", linNumber);
	    exit(0);
	  }
	type = COMMENTS_TOKEN;
      	comment = 1;
      }

    else if (first == ';')
      {
	type = SEMICOLON_TOKEN;
      }

    else if (first == '(')
      {
	type = LEFT_PAREN_TOKEN;
      }

    else if (first == ')')
      {
	type = RIGHT_PAREN_TOKEN;
      }

    else if (first == '<')
      {
	type = LESS_TOKEN;
      }

    else if (first == '>')
      {
	type = GREATER_TOKEN;
      }

    else if (first == '\n')
      {
	type = NEWLINE_TOKEN;
	linNumber++;
	comment = 0;
      }

    else //unknown character 
      {
	type = MISC_TOKEN;
      }
    //idea is to figure out how long the word length is and then use token adding part to figure out how far to add the words.  Also, make sure you move ahead in the outer loop.  This will also overwrite MISC_TOKEN if word is found
    int wordlength = 1;
    int placeholder = bufferIteratorT;
    if (isWordChar(first))  
      {
	type = WORD_TOKEN;
	
	while (isWordChar(buffer[bufferIteratorT+wordlength]))
	  {
	    wordlength++;
	  }
        bufferIteratorT += wordlength-1;
	//	printf("placeholder: %d + \n" , placeholder);
	//printf("end: %d \n", bufferIteratorT);
      }

    //token insertion here.
    if (first == ' ' || first == '\t' || comment == 1)
      {
	//Don't insert
      }
    else 
      {
	token temp;
	temp.type = type;
	temp.linNum = linNumber;
	if ( type == WORD_TOKEN)
	  {
	    temp.words = (char*) checked_malloc ((sizeof(char)*wordlength)+1);
	    int i = 0;
	    for (; i != wordlength;i++)
	    {
	    	temp.words[i] = buffer[placeholder+i]; 
	    }
	    temp.words[i] = '\0';
	  }
	else
	  {
	    temp.words = NULL;	
	  }
	//now insert into token stream
	token_stream* temp_ts = (token_stream*) checked_malloc(sizeof(token_stream*));
	temp_ts->m_token = temp;  
	//might have a serious problem here because if m_token is just a copy of 
	//temp and temp gets erased because temp goes out of scope (e.g. out of this function), 
	//temp might get erased and that also deletes our character array for words, leaving a dangling pointer.
	temp_ts->next = NULL;
	temp_ts->prev = trackend;
	trackend->next = temp_ts;
	trackend = temp_ts;
      }
    bufferIteratorT++;
  }
  
  //now tstream should point to the beginning of a token stream
  //the issue is we initialize the tstream to a blank token so happens is the first token_stream in tstream is empty so we skip it.

  tstream = tstream->next;
  
  //=========Code that outputs the tokens so we can test them============//
  
  puts("WORD_TOKEN: 0 \nSEMICOLON_TOKEN: 1 \nPIPE_TOKEN: 2 \nAND_TOKEN: 3 \nOR_TOKEN: 4 \nLEFT_PAREN_TOKEN: 5 \nRIGHT_PAREN_TOKEN: 6 \nGREATER_TOKEN: 7 \nLESS_TOKEN: 8 \nCOMMENTS_TOKEN: 9 \nNEWLINE_TOKEN: 10 \nMISC_TOKEN: 11 \n");
  
  //puts(tstream->m_token.words);
  /*
  while (tstream->next != NULL)
    {
      //printf("%d \n", tstream->m_token.type);
      //the above line works to display just the tokens, the below doesn't work because there's a segfault on accessing the token words
      if (tstream->m_token.type == WORD_TOKEN)
	{
	  printf("%d:%i: ", tstream->m_token.type, tstream->m_token.linNum);
	puts(tstream->m_token.words);
	//puts("\n");
	}
      else
	printf("%d:%i \n", tstream->m_token.type, tstream->m_token.linNum);
    
      tstream = tstream->next;
    }
printf("%d \n", tstream->m_token.type);
  */

  //=========Code that checks for input errors and validates the tokens before parsing tokens into commands============//

  int leftParenCount = 0;
  int rightParenCount = 0;
  while (tstream != NULL)
  {

    //MISC_TOKENS find inputs not in our subset syntax
    if (tstream->m_token.type == MISC_TOKEN)
      {
       fprintf(stderr,"%i: problem at this line in script\n", tstream->m_token.linNum);
       exit(0);
      }

    //Do count of parentheses 
    if (tstream->m_token.type == LEFT_PAREN_TOKEN)
      leftParenCount++;
    if (tstream->m_token.type == RIGHT_PAREN_TOKEN)
      rightParenCount++;
    if (tstream->next == NULL && leftParenCount != rightParenCount)
      {
	fprintf(stderr,"%i: Unmatching Parentheses\n", tstream->m_token.linNum);  //not sure about this
	exit(0);
      }      

    //Redirec always followed by a word.
    if (tstream->m_token.type == LESS_TOKEN || tstream->m_token.type == GREATER_TOKEN)
      {
	if (tstream->next == NULL)
	  {
	    fprintf(stderr,"%i: Redirect Needs a word following it.\n", tstream->m_token.linNum);
	    exit(0);
	  }
	else if (tstream->next->m_token.type != WORD_TOKEN)
          {
	    fprintf(stderr,"%i: Need word after redirect\n", tstream->m_token.linNum);  
	    exit(0);
	  }        
      }
   
    //Newlines have some specific places they can appear in.
    if (tstream->m_token.type == NEWLINE_TOKEN)
      {
	//check the ones after it for ( ) or words
	if (tstream->next != NULL)
	  {
	    if (tstream->next->m_token.type == LEFT_PAREN_TOKEN || tstream->next->m_token.type == RIGHT_PAREN_TOKEN || tstream->next->m_token.type == WORD_TOKEN)
	      {}
	    else
	      {
		fprintf(stderr,"%i: newline is followed by (,), or words\n", tstream->m_token.linNum);  
		exit(0);
	      }        
	  }
      }

    tstream = tstream->next;
  }
  
      // idea here it to represent problems parsing the code with MISC_TOKEN and have code up in the tokenization part where if the 
      //token is a MISC token, store the line number into the char* words array and if we detect it here, then output it with the line number.

  //=========Changes the tokens into commands============//
  command_stream_t fake = (command_stream_t) checked_malloc(sizeof(command_stream_t));
  fake->size = 1;
  fake->iterator = 0;
  return fake;
}
void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView)
{
	//Get selection
	CharacterRange range = pHighlightView->getSelection();

	//Clear marks
	pHighlightView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_SMART);

	//If nothing selected, dont mark anything
	if (range.cpMin == range.cpMax)
	{
		return;
	}

	int textlen = range.cpMax - range.cpMin + 1;

	char * text2Find = new char[textlen];
	pHighlightView->getSelectedText(text2Find, textlen, false);	//do not expand selection (false)

	
	//GETWORDCHARS for isQualifiedWord2() and isWordChar2()
	int listCharSize = pHighlightView->execute(SCI_GETWORDCHARS, 0, 0);
	char *listChar = new char[listCharSize+1];
	pHighlightView->execute(SCI_GETWORDCHARS, 0, (LPARAM)listChar);
	
	bool valid = true;
	//The word has to consist if wordChars only, and the characters before and after something else
	if (!isQualifiedWord(text2Find, listChar))
		valid = false;
	else
	{
		UCHAR c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMax);
		if (c)
		{
			if (isWordChar(char(c), listChar))
				valid = false;
		}
		c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMin-1);
		if (c)
		{
			if (isWordChar(char(c), listChar))
				valid = false;
		}
	}
	if (!valid) {
		delete [] text2Find;
		delete [] listChar;
		return;
	}

	// save target locations for other search functions
	int originalStartPos = (int)pHighlightView->execute(SCI_GETTARGETSTART);
	int originalEndPos = (int)pHighlightView->execute(SCI_GETTARGETEND);

	// Get the range of text visible and highlight everything in it
	int firstLine =		(int)pHighlightView->execute(SCI_GETFIRSTVISIBLELINE);
	int nrLines =	min((int)pHighlightView->execute(SCI_LINESONSCREEN), MAXLINEHIGHLIGHT ) + 1;
	int lastLine =		firstLine+nrLines;
	int startPos =		0;
	int endPos =		0;
	int currentLine = firstLine;
	int prevDocLineChecked = -1;	//invalid start

	const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();

	FindOption fo;
	fo._isMatchCase = nppGUI._smartHiliteCaseSensitive;
	fo._isWholeWord = true;

	const TCHAR * searchText = NULL;

	WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
	unsigned int cp = pHighlightView->execute(SCI_GETCODEPAGE); 
	const TCHAR * text2FindW = wmc->char2wchar(text2Find, cp);
	searchText = text2FindW;

	for(; currentLine < lastLine; ++currentLine)
	{
		int docLine = (int)pHighlightView->execute(SCI_DOCLINEFROMVISIBLE, currentLine);
		if (docLine == prevDocLineChecked)
			continue;	//still on same line (wordwrap)
		prevDocLineChecked = docLine;
		startPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine);
		endPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine+1);
		if (endPos == -1) {	//past EOF
			endPos = (int)pHighlightView->getCurrentDocLen() - 1;
			_pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo);
			break;
		} else {
			_pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo);
		}
	}

	// restore the original targets to avoid conflicts with the search/replace functions
	pHighlightView->execute(SCI_SETTARGETSTART, originalStartPos);
	pHighlightView->execute(SCI_SETTARGETEND, originalEndPos);
	delete [] listChar;
}
示例#22
0
void testAutocomplete()
{
	int len = fn(ptr, SCI_GETCURLINE, 0, 0);
	if (len <= 2) return;
	char *c = new char[len + 1];
	int caret = fn(ptr, SCI_GETCURLINE, len + 1, (sptr_t)c);
	std::string part;

	static std::string lastList;

	// FOR NOW, require that caret is at eol

	if (caret == len - 1)
	{
		bool money = false;
		for (--caret; caret >= 2 && isWordChar(c[caret]); caret--){ if (c[caret] == '$' || c[caret] == '@') money = true; }
		caret++;
		int slen = strlen(&(c[caret]));
		if (slen > 1)
		{
			std::string str = &(c[caret]);

			if (money)
			{
				std::string token = "";
				int midx = 0;
				for (int i = 1; i < slen; i++) if (str[i] == '$' || str[i] == '@') midx = i ;
				if (midx > 0) token = std::string(str.begin(), str.begin() + midx);
				if (token.compare(moneyToken))
				{
					int sc;
					moneyList.clear();
					moneyList.reserve(100);
					std::vector< std::string > sv;
					sv.push_back(token);
					SafeCall(SCC_NAMES, &sv, &sc);
					moneyToken = token;
				}
			}

			SVECTOR::iterator iter = std::lower_bound(money ? moneyList.begin() : wordList.begin(), money ? moneyList.end() : wordList.end(), str);
			c[len - 2]++;
			str = &(c[caret]);
			SVECTOR::iterator iter2 = std::lower_bound(money ? moneyList.begin() : wordList.begin(), money ? moneyList.end() : wordList.end(), str);
			int count = iter2 - iter;

			str = "";
			if (count > 0 && count <= MAX_AUTOCOMPLETE_LIST_LEN)
			{
				DebugOut("count %d\n", count);

				for (count = 0; iter < iter2; iter++, count++)
				{
					if (count) str += " ";
					str += iter->c_str();
				}

				if ( !fn(ptr, SCI_AUTOCACTIVE, 0, 0 ) || lastList.compare(str))
					fn(ptr, SCI_AUTOCSHOW, slen, (sptr_t)(str.c_str()));
				lastList = str;
			}
		}
	}

	// TODO: optimize this over a single bit of typing...

	caret = fn(ptr, SCI_GETCURLINE, len + 1, (sptr_t)c);
	std::string sc(c, c + caret);

	static std::string empty = "";
	static std::regex bparen("\\([^\\(]*?\\)");
	static std::regex rex("[^\\w\\._\\$]([\\w\\._\\$]+)\\s*\\([^\\)\\(]*$");
	static std::string lasttip;

	while (std::regex_search(sc, bparen))
		sc = regex_replace(sc, bparen, empty);

	std::smatch mat;

	bool ctvisible = fn(ptr, SCI_CALLTIPACTIVE, 0, 0);

	// so there is the possibility that we have a tip because we're in one
	// function, but then we close the tip and fall into an enclosing 
	// function... actually my regex doesn't work, then.

	if (std::regex_search(sc, mat, rex) /* && !ctvisible */)
	{
		std::string tip;
		std::string sym(mat[1].first, mat[1].second);

		if (sym.compare(lasttip))
		{
			int sc = 0;
			std::vector< std::string > sv;
			sv.push_back(sym);
			SafeCall(SCC_CALLTIP, &sv, &sc);
			tip = calltip;

			// if(0)// (getCallTip(tip, sym))
			if (sc)
			{
				DebugOut("%s: %s\n", sym.c_str(), tip.c_str());

				int pos = fn(ptr, SCI_GETCURRENTPOS, 0, 0);
				// pos -= caret; // start of line
				pos -= (mat[0].second - mat[0].first - 1); // this is not correct b/c we are munging the string
				fn(ptr, SCI_CALLTIPSHOW, pos, (sptr_t)tip.c_str());
			}
			else if (ctvisible) fn(ptr, SCI_CALLTIPCANCEL, 0, 0);
			lasttip = sym;
		}
	}
	else
	{
		if (ctvisible) fn(ptr, SCI_CALLTIPCANCEL, 0, 0);
		lasttip = "";
	}

	delete[] c;

}
示例#23
0
void Label::mouseClicked(MouseEventDetails* const e)
{    
    if(getTextSelectable())
    {
        Int32 Position(0);
        Int32 BeginWord = 0;
        Int32 EndWord = getText().size();
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {

            if(e->getClickCount() == 2)
            {
                Pnt2f TopLeftText, BottomRightText, TempPos;
                Pnt2f TopLeftText1, BottomRightText1;
                Pnt2f TopLeft, BottomRight;
                getFont()->getBounds(getText(), TopLeftText, BottomRightText);
                getInsideBorderBounds(TopLeft, BottomRight);
                TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());

                //set caret position to proper place
                //if the mouse is to the left of the text, set it to the begining.
                Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
                if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
                {
                    Position = 0;
                }//if the mouse is to the right of the text, set it to the end
                else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
                {
                    Position = getText().size();
                }
                else
                {
                    for(UInt32 i = 0; i <getText().size(); i++)
                    {        
                        calculateTextBounds(0,i, TopLeftText, BottomRightText);
                        calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                           && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                        {
                            Position = i;
                            break;
                        }
                    }
                }
                if(isPunctuationChar(getText()[Position]))
                {
                    EndWord = Position + 1;
                    BeginWord = Position;
                }
                else{
                    for(Int32 i = Position; i < getText().size(); i++)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            EndWord = i;
                            break;
                        }
                    }
                    for(Int32 i = Position; i >= 0; i--)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            BeginWord = i + 1;
                            break;
                        }
                    }
                }
                _TextSelectionEnd = EndWord;
                _TextSelectionStart = BeginWord;
                setCaretPosition(EndWord);
            }
        }
    }
    Inherited::mouseClicked(e);

}
void FixedHeightLayoutManager::moveAndHighlightWord(UInt32 dir)
{
	Int32 prevIndex= _CaretIndex;
	Int32 prevLine= _CaretLine;
	bool fromPrevElement = false;
	PlainDocumentLeafElementRefPtr theElement; 
	std::string theString;

	switch(dir)
	{

	case LEFT:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));

		if(prevIndex == 0)
		{
			if(prevLine>0)
			{
				prevLine--;
				theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));
				prevIndex = theElement->getTextLength()-2;
				_CaretLine = prevLine;
				_CaretIndex = prevIndex;
				fromPrevElement = true;
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-2);
			}
			else break;
		}

		theString = theElement->getText();

		if(prevIndex>0 && isWordChar(theString[prevIndex-1]) == false)fromPrevElement = true;

		for(Int32 i=prevIndex-1; i>=0;)
		{
			if(isWordChar(theString[i]) != fromPrevElement) // this means that when prevIndex is 0, it would indicate the beginning of the line and hence, the ctrl action should take the cursor until a wordchar is found
			{
				_CaretLine = prevLine;
				_CaretIndex = i;	
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-1);
				i--;
			}
			else
			{
				break;
			}
		}
		recalculateCaretPositions();
		break;	// case left complete.

	case RIGHT:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));

		if(prevIndex >=theElement->getTextLength()-2)
		{
			if(prevLine<rootElement->getElementCount()-1)
			{
				prevLine++;
				prevIndex = 0;
				_CaretLine = prevLine;
				_CaretIndex = prevIndex;
				fromPrevElement = true;
				theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+2);
			}
			else break;
		}

		theString = theElement->getText();

		if(isWordChar(theString[prevIndex]) == false)fromPrevElement = true;

		for(UInt32 i=prevIndex; i<theElement->getTextLength()-2;)
		{
			if(isWordChar(theString[i]) != fromPrevElement) // this means that when prevIndex is 0, it would indicate the beginning of the line and hence, the ctrl action should take the cursor until a wordchar is found
			{
				i++;
				_CaretLine = prevLine;
				_CaretIndex = i;	
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+1);
			}
			else
			{
				break;
			}
		}
		recalculateCaretPositions();
		break;	// Case Right complete.
	}
}
示例#25
0
static void
getToken(xmlrpc_env *   const envP,
         Tokenizer * const tokP) {

    /* The token starts where the last one left off */
    tokP->begin = tokP->end;

    advanceToNextToken(tokP);

    if (*tokP->begin == '\0') {
        /* End of document */
        tokP->end = tokP->begin;
        tokP->type = typeEof;
        tokP->size = tokP->end - tokP->begin;
    } else {
        tokP->end = tokP->begin;  /* initial value */
    
        if (*tokP->begin == '{') {
            finishDelimiterToken(tokP);
            tokP->type = typeOpenBrace;
        } else if (*tokP->begin == '}') {
            finishDelimiterToken(tokP);
            tokP->type = typeCloseBrace;
        } else if (*tokP->begin == '[') {
            finishDelimiterToken(tokP);
            tokP->type = typeOpenBracket;
        } else if (*tokP->begin == ']') {
            finishDelimiterToken(tokP);
            tokP->type = typeCloseBracket;
        } else if (*tokP->begin == ':') {
            finishDelimiterToken(tokP);
            tokP->type = typeColon;
        } else if (*tokP->begin == ',') {
            finishDelimiterToken(tokP);
            tokP->type = typeComma;
        } else if (*tokP->begin == '"') {
            finishStringToken(envP, tokP);

            if (!envP->fault_occurred)
                tokP->type = typeString;
        } else {
            if (isWordChar(*tokP->begin)) {
                finishAlphanumericWordToken(tokP);

                if (isInteger(tokP->begin, tokP->size))
                    tokP->type = typeInteger;
                else if (isFloat(tokP->begin, tokP->size))
                    tokP->type = typeFloat;
                else if (xmlrpc_strneq(tokP->begin, "null", tokP->size))
                    tokP->type = typeNull;
                else if (xmlrpc_strneq(tokP->begin, "undefined", tokP->size))
                    tokP->type = typeUndefined;
                else if(xmlrpc_strneq(tokP->begin, "false", tokP->size))
                    tokP->type = typeFalse;
                else if(xmlrpc_strneq(tokP->begin, "true", tokP->size))
                    tokP->type = typeTrue;
                else
                    setParseErr(envP, tokP, "Invalid word token -- "
                                "Not a valid integer, floating point "
                                "number, 'null', 'true', or 'false'");
            } else {
                setParseErr(envP, tokP,
                            "Not a valid token -- starts with '%c'; "
                            "a valid token starts with "
                            "one of []{}:,\"-. or digit or letter",
                            *tokP->begin);
            }
        }
    }
}
示例#26
0
Token* Tokenizer::getToken()
{
	int startRow = row;
	int startCol = col;

	QChar c = getChar();  // get and store the next character from the string

	// catch the end of the input string
	if (atEnd)
		return new Token(Token::EndOfInput, "END", row, col, row, col);

	int cType = translator->look2type(c);  // since we need to know it often we store it

	// catch spaces
	if (isSpace(c)) {
		QString look;
		do {
			look += (isTab(c) ? "  " : " ");
			c = getChar();
		} while (isSpace(c) && !atEnd);
		ungetChar();
		return new Token(Token::WhiteSpace, look, startRow, startCol, row, col);
	}

	// catch EndOfLine's
	if (isBreak(c)) {
		return new Token(Token::EndOfLine, "\\n", startRow, startCol, startRow+1, 1);
	}

	// catch comments
	if (cType == Token::Comment) {
		QString look;
		do {
			look += c;
			c = getChar();
		} while (!isBreak(c) && !atEnd);
		ungetChar();
		return new Token(Token::Comment, look, startRow, startCol, row, col);
	}

	// catch strings
	if (cType == Token::StringDelimiter) {
		QString look = QString(c);
		do {
			c = getChar();
			look += c;
		} while (!(translator->look2type(c) == Token::StringDelimiter && look.right(2) != "\\\"") &&
		         !isBreak(c) && !atEnd);
		return new Token(Token::String, look, startRow, startCol, row, col);
	}

	// catch variables
	if (cType == Token::VariablePrefix) {
		QString look;
		do {
			look += c;
			c = getChar();
		} while (isWordChar(c) || c.category() == QChar::Number_DecimalDigit || c == '_');
		ungetChar();
		return new Token(Token::Variable, look, startRow, startCol, row, col);
	}

	// catch words (known commands or function calls)
	if (isWordChar(c)) {  // first char has to be a letter
		QString look;
		do {
			look += c;
			c = getChar();
		} while (isWordChar(c) || c.isDigit() || c == '_');  // next chars
		ungetChar();
		int type = translator->look2type(look);
		if (type == Token::Unknown)
			type = Token::FunctionCall;
		return new Token(type, look, startRow, startCol, row, col);
	}

	// catch numbers
	if (c.isDigit() || cType == Token::DecimalSeparator) {
		bool hasDot = false;

		int localType = cType;
		QString look;
		do {
			if (localType == Token::DecimalSeparator) hasDot = true;
			look += c;
			c = getChar();
			localType = translator->look2type(c);
		} while (c.isDigit() || (localType == Token::DecimalSeparator && !hasDot));
		ungetChar();
		
		// if all we got is a dot then this is not a number, so return an Error token here
		if (translator->look2type(look) == Token::DecimalSeparator)
			return new Token(Token::Error, look, startRow, startCol, row, col);
		
		return new Token(Token::Number, look, startRow, startCol, row, col);
	}

	// catch previously uncatched 'double charactered tokens' (tokens that ar not in letters, like: == != >= <=)
	{
		QString look = QString(c).append(getChar());
		int type = translator->look2type(look);
		if (type != Token::Unknown)
			return new Token(type, look, startRow, startCol, row, col);
		ungetChar();
	}

	// catch known tokens of a single character (as last...)
	if (cType != Token::Unknown)
		return new Token(cType, static_cast<QString>(c), startRow, startCol, row, col);

	// this does not neglect calls to functions with a name of length one (checked it)
	return new Token(Token::Error, static_cast<QString>(c), startRow, startCol, row, col);
}
示例#27
0
文件: vim.c 项目: Monits/ctags
static const unsigned char *skipWord(const unsigned char *p)
{
	while (*p && isWordChar (*p))
		p++;
	return p;
}
示例#28
0
command_stream_t
make_command_stream(int (*get_next_byte) (void *),
                    void *get_next_byte_argument)
{

    //building the stream string
    int lineNum = 1;

    ////printf("Step 1: Building the buffer string.\n");
    char currChar;
    char* buffer = (char*) checked_malloc(sizeof(char));
    int bufferSize = 0;
    while((currChar = get_next_byte(get_next_byte_argument)) != EOF)
    {
        if(currChar == '\n')
        {
            lineNum++;
        }
        if(!isCharValid(currChar))
        {
            error(1,0,"%d: Syntax error (Illegal character %c found.) \n", lineNum, currChar);
        }
        else if (currChar == '#')
        {
            //while(currChar != '\n' && currChar != EOF)
            while((currChar = get_next_byte(get_next_byte_argument)) != EOF && currChar != '\n')
            {
            }
            if(feof(get_next_byte_argument))
            {
                error(1,0,"%d: Syntax error (Comments need to be terminated with new line)\n", lineNum);
            }
            else
            {
                lineNum++;
            }
        }
        buffer[bufferSize] = currChar;
        bufferSize++;
        buffer = (char*)checked_realloc(buffer, bufferSize+1);
    }
    buffer[bufferSize] = '\0';
    ////printf("Step 1: Buffer Built \n%s\n Strlen(buffer) = %d, bufferSize = %d\n", buffer, strlen(buffer), bufferSize);


    ////printf("Step 2: Clean up iteration started.\n");
    lineNum = 1;
    int prev = -1;
    int n; //next nonwhite space index
    int curr = nextIndex(buffer, bufferSize, -1);
    int next = nextIndex(buffer, bufferSize, curr);
    while (curr < bufferSize)
    {
        ////printf("Step 2: prev = %d, curr = %d, next = %d.\n", prev, curr, next);
        switch (buffer[curr])
        {
        case ';':
            n = nextNonwhitespace(buffer, bufferSize, curr);
            if ((prev==-1) || (n == bufferSize)
                    || !(isWordChar(buffer[prev])||buffer[prev] == ')')  //(;) );(
                    || !(isWordChar(buffer[n])||buffer[n] == '('))
            {
                error(1,0,"%d: Syntax error (Incomplete operators %c found)\n", lineNum, buffer[curr]);
            }
            break;
        case '>':
        case '<':
            //if ((prev==-1) || (nextNonwhitespace(buffer, bufferSize, curr) == bufferSize)
            //  ||(isOperator(buffer[prev])) || (isOperator(buffer[next])))
            if ((prev==-1) || (nextNonwhitespace(buffer, bufferSize, curr) == bufferSize)
                    || !isWordChar(buffer[prev]) || !isWordChar(buffer[next]))
            {
                error(1,0,"%d: Syntax error (Incomplete operators %c found)\n", lineNum, buffer[curr]);
            }
            break;
        case '&':
            if (buffer[next] == '&' && next-curr == 1)
            {
                buffer[curr] = '*';
                buffer[next] = ' ';
                next = nextIndex(buffer, bufferSize, curr);
                n = nextNonwhitespace(buffer, bufferSize, curr);
                if ((prev==-1) || (n==bufferSize)
                        || !(isWordChar(buffer[prev])||buffer[prev] == ')')  //(;) );(
                        || !(isWordChar(buffer[n])||buffer[n] == '('))
                {
                    error(1,0,"%d: Syntax error (Incomplete operators %c found)\n", lineNum, buffer[curr]);
                }
            }
            else
            {
                error(1,0,"%d: Syntax error (Incomplete operators %c found)\n", lineNum, buffer[curr]);
            }
            break;
        case '|':
            if (buffer[next] == '|' && next-curr == 1)
            {
                buffer[curr] = '$';
                buffer[next] = ' ';
                next = nextIndex(buffer, bufferSize, curr);
            }
            n = nextNonwhitespace(buffer, bufferSize, curr);
            if ((prev==-1) || (n==bufferSize)
                    || !(isWordChar(buffer[prev])||buffer[prev] == ')')  //(;) );(
                    || !(isWordChar(buffer[n])||buffer[n] == '('))
            {
                error(1,0,"%d: Syntax error (Incomplete operators %c found)\n", lineNum, buffer[curr]);
            }
            break;
        case '\n':
            if ((prev!=-1) && (buffer[prev] == '<' || buffer[prev] == '>'))
            {
                error(1,0,"%d: Syntax error (New line character can only follow tokens other than < >.)\n", lineNum);
            }

            if (buffer[next] == '\n')
            {
                if(buffer[prev] != '$' && buffer[prev] != '*' && buffer[prev] != '|')
                {
                    buffer[curr] = '@';
                }
                else
                {
                    buffer[curr] = ' ';
                }
                buffer[next] = ' ';
                lineNum++;
                next = nextIndex(buffer, bufferSize, next);
                while (buffer[next] == '\n')
                {
                    buffer[next] = ' ';
                    next = nextIndex(buffer, bufferSize, next);
                    lineNum++;
                }
            }
            else if ((prev!=-1) && (next!=bufferSize) && ((isOperator(buffer[prev])) || (buffer[prev]=='(')))
            {
                buffer[curr] = ' ';
            }
            else if ((prev!=-1) && (next!=bufferSize) && ((isWordChar(buffer[prev])) || (buffer[prev]==')')))
            {
                buffer[curr] = ';';
            }

            if ((next!=bufferSize)
                    && (!(buffer[next] == '(' || buffer[next]==')' || isWordChar(buffer[next]))))
            {
                error(1,0,"%d, Syntax error (New line character can only be followed by (, ), or Words.)\n", lineNum);
            }

            lineNum++;
            break;
        }
        prev = curr;
        curr = next;
        next = nextIndex(buffer, bufferSize, curr);
    }
    ////printf("Step 2: Buffer cleaned \n%s\n Strlen(buffer) = %d, bufferSize = %d\n", buffer, strlen(buffer), bufferSize);

    ////printf("Step 3: Parenthesis check start.\n");
    int stackSize = 0;
    int i;
    for (i = 0; i < bufferSize; i++)
    {
        if (buffer[i] == '(')
        {
            stackSize++;
        }
        else if (buffer[i] == ')')
        {
            if(stackSize > 0)
            {
                stackSize--;
            }
            else
            {
                error(1,0,"Syntax error (Unbalanced parenthesis found)\n");
            }
        }
    }
    if (stackSize > 0)
    {
        error(1,0,"Syntax error (Unbalanced parenthesis found)");
    }
    ////printf("Step 3: Parenthesis check complete.\n");

    ////printf("Step 4: Outputting\n");
    command_stream_t cstream = (command_stream_t) checked_malloc(sizeof(struct command_stream));
    cstream->stream = buffer;
    cstream->index = 0;
    if (debug) printf("Buffer: \"%s\"\n", buffer);

    return cstream;
}
示例#29
0
		void ChatWindow::AddMessage(const std::string &msg){
			SPADES_MARK_FUNCTION();
			
			ChatEntry ent;
			
			// get visible message string
			std::string str;
			float x = 0.f, maxW = GetWidth();
			float lh = GetLineHeight(), h = lh;
			size_t wordStart = std::string::npos;
			size_t wordStartOutPos;
			
			for(size_t i = 0; i < msg.size(); i++){
				if(msg[i] > MsgColorMax &&
				   msg[i] != 13 && msg[i] != 10){
					if(isWordChar(msg[i])){
						if(wordStart == std::string::npos){
							wordStart = msg.size();
							wordStartOutPos = str.size();
						}
					}else{
						wordStart = std::string::npos;
					}
					
					float w = font->Measure(std::string(&msg[i],1)).x;
					if(x + w > maxW){
						if(wordStart != std::string::npos &&
						   wordStart != str.size()){
							// adding a part of word.
							// do word wrapping
							
							std::string s = msg.substr(wordStart, i - wordStart + 1);
							float nw = font->Measure(s).x;
							if(nw <= maxW){
								// word wrap succeeds
								
								w = nw;
								x = w;
								h += lh;
								str.insert(wordStartOutPos, "\n");
								
								goto didWordWrap;
							}
							
						}
						x = 0; h += lh;
						str += 13;
					}
					x += w;
					str += msg[i];
				didWordWrap:;
				}else if(msg[i] == 13 || msg[i] == 10){
					x = 0; h += lh;
					str += 13;
				}else{
					str += msg[i];
				}
			}
			
			ent.height = h;
			ent.msg = msg;
			ent.fade = 0.f;
			ent.timeFade = 15.f;
			
			entries.push_front(ent);
			
			firstY -= h;
		}