{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/954","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/954/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/954/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/954/events","html_url":"https://github.com/dotnet/roslyn/issues/954","id":59372293,"number":954,"title":"(Proposal) Make Multiple PeekAheadChar( ) Comparisions simpler","user":{"login":"AdamSpeight2008","id":900107,"avatar_url":"https://avatars.githubusercontent.com/u/900107?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamSpeight2008","html_url":"https://github.com/AdamSpeight2008","followers_url":"https://api.github.com/users/AdamSpeight2008/followers","following_url":"https://api.github.com/users/AdamSpeight2008/following{/other_user}","gists_url":"https://api.github.com/users/AdamSpeight2008/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamSpeight2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamSpeight2008/subscriptions","organizations_url":"https://api.github.com/users/AdamSpeight2008/orgs","repos_url":"https://api.github.com/users/AdamSpeight2008/repos","events_url":"https://api.github.com/users/AdamSpeight2008/events{/privacy}","received_events_url":"https://api.github.com/users/AdamSpeight2008/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-01T02:31:37Z","updated_at":"2015-03-01T05:14:22Z","closed_at":null,"body":"In the [scanner](https://github.com/dotnet/roslyn/blob/master/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb#L1495) there are multiple occasions where we compare the results of multipe calls to `PeekAheadChar` against the characters of a desired sequence of characters. In essences do the following character match this string.\r\n**Example**\r\n```vb\r\nIf CanGetCharAtOffset(length + 8) AndAlso \r\n    PeekAheadChar(length + 2) = \"C\"c AndAlso\r\n    PeekAheadChar(length + 3) = \"D\"c AndAlso \r\n    PeekAheadChar(length + 4) = \"A\"c AndAlso \r\n    PeekAheadChar(length + 5) = \"T\"c AndAlso \r\n    PeekAheadChar(length + 6) = \"A\"c AndAlso \r\n    PeekAheadChar(length + 7) = \"[\"c Then \r\n        Return XmlMakeBeginCDataToken(precedingTrivia, scanTrailingTrivia) \r\nEnd If \r\n```\r\nIt would make the code much simpler if this was abstracted in to a function.\r\nI propose the functon name of **NextAre** as it scans good with current conditionals (of If / When)\r\n\r\n```vb\r\nIf NextAre(8,2,\"CDATA[\") Then Return XmlMakeBeginCDataToken(precedingTrivia, scanTrailingTrivia)\r\n```\r\n```vb\r\nCase \"[\"c When NextAre(8,2,\"CDATA[\")  :  Return XmlMakeBeginCDataToken(precedingTrivia, scanTrailingTrivia)\r\n```\r\n\r\n--------\r\n\r\n**Implementation**\r\n\r\n```vb\r\nFunction NextAre( at As Integer , text As String ) As Boolean\r\n  Return NextAre( at,1,text)\r\nEnd Function\r\n\r\nFunction NextAre( at As Integer, start As Integer, text As String ) As Boolean\r\n  If text Is Nothing Then Return False\r\n  Dim n = word.length\r\n  If Not CanGetCharAtOffset( at+n ) Then Return False\r\n  Dim startAt = at + start\r\n  Dim i=0\r\n  While i < n\r\n    If PeekAheadChar( startAt+i ) <> text( i ) Then Return False\r\n    i+=1\r\n  End While\r\n  Return True\r\nEnd Function\r\n```\r\n**Note:** ```start + text.Length = at``` seems to hold true, which if that is the case then the parameters of the function can be reduced to two. ```( start As Integer, text As String ) As Boolean``` \r\nSo is there any existing use case (in roslyn) where this isn't the case."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/76574820","html_url":"https://github.com/dotnet/roslyn/issues/954#issuecomment-76574820","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/954","id":76574820,"user":{"login":"AdamSpeight2008","id":900107,"avatar_url":"https://avatars.githubusercontent.com/u/900107?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamSpeight2008","html_url":"https://github.com/AdamSpeight2008","followers_url":"https://api.github.com/users/AdamSpeight2008/followers","following_url":"https://api.github.com/users/AdamSpeight2008/following{/other_user}","gists_url":"https://api.github.com/users/AdamSpeight2008/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamSpeight2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamSpeight2008/subscriptions","organizations_url":"https://api.github.com/users/AdamSpeight2008/orgs","repos_url":"https://api.github.com/users/AdamSpeight2008/repos","events_url":"https://api.github.com/users/AdamSpeight2008/events{/privacy}","received_events_url":"https://api.github.com/users/AdamSpeight2008/received_events","type":"User","site_admin":false},"created_at":"2015-03-01T05:14:22Z","updated_at":"2015-03-01T05:14:22Z","body":"> @mikedn (re: #943)\r\n> Large look ahead cases like the one you link to would probably be better served by something like  PeekAheadString(3, \"CDATA[\") , a single method call instead of 7."}}