Closed Bug 1679987 Opened 5 years ago Closed 5 years ago

Allow nsTCharSeparatedTokenizer to be used in a range-based for loop

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
86 Branch
Tracking Status
firefox86 --- fixed

People

(Reporter: sg, Assigned: sg)

Details

Attachments

(7 files)

At the moment, using nsTCharSeparatedTokenizer (and its specializations) requires custom while loops like

      nsCCharSeparatedTokenizer tokenizer(headerValue, ';');
      while (tokenizer.hasMoreTokens()) {
        const nsDependentCSubstring& token = tokenizer.nextToken();

        // do something with token
      }

With an appropriate adapter, C++11 range-based for loops could be used instead, which would provide a simpler syntax, reduce scope of the tokenizer and increase regularity:

      for (const nsDependentCSubstring& token :
           nsTokenizedRange{nsCCharSeparatedTokenizer(headerValue, ';')}) {
        // do something with token
      }

Also, several uses of strtok could be transformed to use the tokenizers in a range-based way.

Please provide an explanation of what you are doing and why. The two major parts of the review process are determining whether the goals of the author are good and whether they are being achieved, and without knowing what you are trying to do, that makes review much more difficult. Thanks.

Flags: needinfo?(sgiesecke)

(In reply to Andrew McCreight [:mccr8] from comment #5)

Please provide an explanation of what you are doing and why. The two major parts of the review process are determining whether the goals of the author are good and whether they are being achieved, and without knowing what you are trying to do, that makes review much more difficult. Thanks.

Sorry, I added a description now.

Flags: needinfo?(sgiesecke)
Attachment #9192196 - Attachment description: Bug 1679987 - Split using nsTokenizedRange. r=#xpcom-reviewers → Bug 1679987 - Implement nsTSubstring::Split using nsTokenizedRange. r=#xpcom-reviewers
Component: String → XPCOM

There are no uses of nsTCharSeparatedTokenizer that require run-time
configuration of the flags, so having them a compile-time template
argument allows for generation of more efficient code.

This might not matter that much now, but a subsequent patch will add another
flag to allow merging the implementation of nsTSubstring::Split with
nsTCharSeparatedTokenizer, through which the compile-time evaluation will
become more relevant.

Depends on D98307

Attachment #9190519 - Attachment description: Bug 1679987 - Convert tokenizers from classes to functions. r=#xpcom-reviewers → Bug 1679987 - Convert tokenizer specializations from classes to type aliases. r=#xpcom-reviewers
Keywords: leave-open
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/6568490004a6 Removed unused includes of nsCharSeparatedTokenizer.h. r=nika https://hg.mozilla.org/integration/autoland/rev/6cfaa0523589 Convert tokenizer specializations from classes to type aliases. r=xpcom-reviewers,nika,necko-reviewers https://hg.mozilla.org/integration/autoland/rev/e94505c67802 Add nsTokenizedRange adapter to enable range-based for with tokenizers. r=xpcom-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/ad59c7dccefb Make nsTokenizerFlags a scoped enum and make them a template argument to nsTCharSeparatedTokenizer. r=xpcom-reviewers,necko-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/3fb5e713945b Use nsTokenizedRange where easily possible. r=xpcom-reviewers,nika https://hg.mozilla.org/integration/autoland/rev/f84ee933797d Replace strtok for Vary header by nsCCharSeparatedTokenizer and range-based for. r=necko-reviewers,dom-workers-and-storage-reviewers,asuth,valentin
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/aa95b6225a74 Implement nsTSubstring::Split using nsTokenizedRange. r=xpcom-reviewers,necko-reviewers,nika
Keywords: leave-open
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 86 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: