Exemplo n.º 1
0
void
BUrl::_ExplodeUrlString(const BString& url)
{
	// The regexp is provided in RFC3986 (URI generic syntax), Appendix B
	static RegExp urlMatcher(
		"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");

	_ResetFields();

	RegExp::MatchResult match = urlMatcher.Match(url.String());

	if (!match.HasMatched())
		return; // TODO error reporting

	// Scheme/Protocol
	url.CopyInto(fProtocol, match.GroupStartOffsetAt(1),
		match.GroupEndOffsetAt(1) - match.GroupStartOffsetAt(1));
	if (!_IsProtocolValid()) {
		fHasProtocol = false;
		fProtocol.Truncate(0);
	} else
		fHasProtocol = true;

	// Authority (including user credentials, host, and port
	url.CopyInto(fAuthority, match.GroupStartOffsetAt(3),
		match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3));
	SetAuthority(fAuthority);

	// Path
	url.CopyInto(fPath, match.GroupStartOffsetAt(4),
		match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4));
	if (!fPath.IsEmpty())
		fHasPath = true;

	// Query
	url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
		match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
	if (!fRequest.IsEmpty())
		fHasRequest = true;

	// Fragment
	url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
		match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
	if (!fFragment.IsEmpty())
		fHasFragment = true;
}
Exemplo n.º 2
0
TagInfo* ParseLine(const char* buf,const String& base)
{
  String pos;
  String file;
  SMatch m[10];
  int n=10;
  if(reParse.Match(buf,m,n))
  {
    TagInfo *i=new TagInfo;
    SetStr(i->name,buf,m[1]);
    SetStr(file,buf,m[2]);
    if(file[1]!=':' && file[0]!='\\')
    {
      file.Insert(0,base);
    }
    i->file=file;
    SetStr(pos,buf,m[3]);
    if(pos[0]=='/')
    {
      QuoteMeta(pos);
      ReplaceSpaces(pos);
      i->re=pos;
      if(m[5].start!=-1)
      {
        SetStr(pos,buf,m[5]);
        i->lineno=pos.ToInt();
      }
    }else
    {
      i->lineno=pos.ToInt();
    }
    SetStr(pos,buf,m[4]);
    i->type=pos[0];
    if(m[5].start!=-1)
    {
      SetStr(i->info,buf,m[6]);
    }
    return i;
  }
  return NULL;
}
Exemplo n.º 3
0
static bool
match_team_name(const char* teamName, const char* parameterName)
{
    RegExp expressionMatcher;
    if (expressionMatcher.SetPattern(parameterName,
                                     RegExp::PATTERN_TYPE_WILDCARD)) {
        BString value = teamName;
        if (parameterName[0] != '/') {
            // the expression in question is a team name match only,
            // so we need to extract that.
            BPath path(teamName);
            if (path.InitCheck() == B_OK)
                value = path.Leaf();
        }

        RegExp::MatchResult match = expressionMatcher.Match(value);
        if (match.HasMatched())
            return true;
    }

    return false;
}
Exemplo n.º 4
0
static void NavigateTo(TagInfo* info)
{
  DWORD ver=I.AdvControl(I.ModuleNumber,ACTL_GETFARVERSION,NULL);
  int build=(ver&0xffff0000)>>16;
  EditorInfo ei;
  I.EditorControl(ECTL_GETINFO,&ei);
  {
    SUndoInfo ui;
    ui.file=ei.FileName;
    ui.line=ei.CurLine;
    ui.pos=ei.CurPos;
    ui.top=ei.TopScreenLine;
    ui.left=ei.LeftPos;
    UndoArray.Push(ui);
  }
  WindowInfo wi;
  int ok=0;

  const char* file=info->file.Str();
  if(build>1500)
  {
    int c=I.AdvControl(I.ModuleNumber,ACTL_GETWINDOWCOUNT,NULL);
    for(int i=0;i<c;i++)
    {
      wi.Pos=i;
      I.AdvControl(I.ModuleNumber,ACTL_GETWINDOWINFO,(void*)&wi);
      if(wi.Type==WTYPE_EDITOR && !lstrcmpi(wi.Name,file))
      {
        I.AdvControl(I.ModuleNumber,ACTL_SETCURRENTWINDOW,(void*)i);
        //if(mode==MODE_EDITOR)I.AdvControl(I.ModuleNumber,ACTL_COMMIT,(void*)i);
        I.AdvControl(I.ModuleNumber,ACTL_COMMIT,(void*)i);
        ok=1;
        break;
      }
    }
  }
  int havere=info->re.Length()>0;
  RegExp re;
  if(havere)re.Compile(info->re);
  if(!ok)
  {
    FILE *f=fopen(file,"rt");
    if(!f)
    {
      Msg(MEFailedToOpen);
      return;
    }
    int line=info->lineno-1;
    int cnt=0;
    char buf[512];
    while(fgets(buf,sizeof(buf),f) && cnt<line)cnt++;
    chomp(buf);
    SMatch m[10];
    int n=10;
    if(line!=-1)
    {
      if(havere && !re.Match(buf,m,n))
      {
        line=-1;
//        Msg("not found in place, searching");
      }
    }
    if(line==-1)
    {
      if(!havere)
      {
        NotFound(file,info->lineno);
        fclose(f);
        return;
      }
      line=0;
      fseek(f,0,SEEK_SET);
      while(fgets(buf,sizeof(buf),f))
      {
        chomp(buf);
        n=10;
        if(re.Match(buf,m,n))
        {
          break;
        }
        line++;
      }
      if(feof(f))
      {
        NotFound(file,info->lineno);
        fclose(f);
        return;
      }
    }
    fclose(f);
    I.Editor(file,"",0,0,-1,-1,build>1500?EF_NONMODAL:0,line+1,1);
    return;
  }
  EditorSetPosition esp;
  I.EditorControl(ECTL_GETINFO,&ei);

  esp.CurPos=-1;
  esp.CurTabPos=-1;
  esp.TopScreenLine=-1;
  esp.LeftPos=-1;
  esp.Overtype=-1;


  int line=info->lineno-1;
  if(line!=-1)
  {
    EditorGetString egs;
    egs.StringNumber=line;
    I.EditorControl(ECTL_GETSTRING,&egs);
    SMatch m[10];
    int n=10;

    if(havere && !re.Match(egs.StringText,egs.StringText+egs.StringLength,m,n))
    {
      line=-1;
    }
  }
  if(line==-1)
  {
    if(!havere)
    {
      esp.CurLine=ei.CurLine;
      esp.TopScreenLine=ei.TopScreenLine;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      NotFound(file,info->lineno);
      return;
    }
    line=0;
    SMatch m[10];
    int n=10;
    EditorGetString egs;
    while(line<ei.TotalLines)
    {
      esp.CurLine=line;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      egs.StringNumber=-1;
      I.EditorControl(ECTL_GETSTRING,&egs);
      n=10;
      if(re.Match(egs.StringText,egs.StringText+egs.StringLength,m,n))
      {
        break;
      }
      line++;
    }
    if(line==ei.TotalLines)
    {
      esp.CurLine=info->lineno==-1?ei.CurLine:info->lineno-1;
      esp.TopScreenLine=ei.TopScreenLine;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      NotFound(file,info->lineno);
      return;
    }
  }

  esp.CurLine=line;
  esp.TopScreenLine=esp.CurLine-1;
  if(esp.TopScreenLine==-1)esp.TopScreenLine=0;
  if(ei.TotalLines<ei.WindowSizeY)esp.TopScreenLine=0;
  esp.LeftPos=0;
  I.EditorControl(ECTL_SETPOSITION,&esp);
  I.EditorControl(ECTL_REDRAW,NULL);
}