JBoolean
CBStringCompleter::Complete
	(
	JTextEditor*			te,
	const JBoolean			includeNS,
	JXStringCompletionMenu*	menu
	)
{
	assert( menu != NULL );

	JIndex caretIndex;
	if (!te->GetCaretLocation(&caretIndex))
		{
		return kJFalse;
		}

	const JString& text = te->GetText();
	JIndex i            = caretIndex;
	while (i > 1 && IsWordCharacter(text, i-1, includeNS))
		{
		i--;
		}

	if (i == caretIndex)
		{
		return kJFalse;
		}

	JString s;
	const JString prefix   = text.GetSubstring(i, caretIndex-1);
	const JSize matchCount = Complete(prefix, &s, menu);
	if (matchCount > 0 &&
		s.GetLength() > prefix.GetLength())
		{
		s.RemoveSubstring(1, prefix.GetLength());
		te->Paste(s);
		menu->ClearRequestCount();
		return kJTrue;
		}
	else if (matchCount > 1)
		{
		menu->CompletionRequested(prefix.GetLength());
		return kJTrue;
		}
	else if (matchCount == 0 && includeNS)
		{
		// try once more without namespace
		return Complete(te, kJFalse, menu);
		}

	return kJFalse;
}
Esempio n. 2
0
bool wxExTextFile::MatchLine(wxString& line)
{
  bool match = false;
  int count = 1;

  wxExFindReplaceData* frd = wxExFindReplaceData::Get();

  if (!frd->UseRegularExpression() || !frd->GetRegularExpression().IsValid())
  {
    if (m_Tool.GetId() == ID_TOOL_REPORT_FIND)
    {
      std::string search_line(line);

      if (!frd->MatchCase())
      {
        std::transform(
          search_line.begin(), 
          search_line.end(), 
          search_line.begin(), 
          toupper);
      }

      const size_t start = search_line.find(m_FindString);

      if (start != wxString::npos)
      {
        if (frd->MatchWord())
        {
          if (( start == 0 ||
               (start > 0 && !IsWordCharacter(search_line[start - 1]))) &&
              !IsWordCharacter(search_line[start + m_FindString.length()]))
          {
            match = true;
          }
        }
        else
        {
          match = true;
        }
      }
    }
    else
    {
      count = line.Replace(
        frd->GetFindString(), 
        frd->GetReplaceString());

      if (count > 0)
      {
        m_Modified = true;
        match = true;
      }
    }
  }
  else
  {
    match = frd->GetRegularExpression().Matches(line);

    if (match && m_Tool.GetId() == ID_TOOL_REPORT_REPLACE)
    {
      count = frd->GetRegularExpression().ReplaceAll(
        &line, 
        frd->GetReplaceString());

      m_Modified = true;
    }
  }

  if (match)
  {
    IncActionsCompleted(count);
  }

  return match;
}