Skip to content

Add more AsSpan overloads to StringSegment #50428

Closed

Description

@BrennanConroy

Background and Motivation

Many classes provide AsSpan methods and most provide at least the 3 basic methods, AsSpan(), AsSpan(int start), AsSpan(int start, int length).

The StringSegment class only provides AsSpan(), but it should provide the other two for consistency and ease of use.

Proposed API

namespace Microsoft.Extensions.Primitives
{
    public readonly struct StringSegment : IEquatable<StringSegment>, IEquatable<string>
    {
        public ReadOnlySpan<char> AsSpan();
+       public ReadOnlySpan<char> AsSpan(int start);
+       public ReadOnlySpan<char> AsSpan(int start, int length);
    }
}

Usage Examples

// input.AsSpan().Slice(startIndex, typeLength);
input.AsSpan(startIndex, typeLength);

Alternative Designs

No, other classes that provide AsSpan have similar overloads

Risks

None

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Mar 30, 2021
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 30, 2021
  3. added
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    and removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    untriagedNew issue has not been triaged by the area owner
    on Mar 30, 2021
  4. added this to the 6.0.0 milestone on Apr 23, 2021
  5. bartonjs commented on May 27, 2021

    @bartonjs
    Member

    Video

    Looks good as proposed.

    namespace Microsoft.Extensions.Primitives
    {
        partial struct StringSegment : IEquatable<StringSegment>, IEquatable<string>
        {
           public ReadOnlySpan<char> AsSpan(int start);
           public ReadOnlySpan<char> AsSpan(int start, int length);
        }
    }
  6. added
    api-approvedAPI was approved in API review, it can be implemented
    and removed
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    on May 27, 2021
  7. gfoidl commented on May 28, 2021

    @gfoidl
    Member

    I'd like to add these overloads.

  8. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 29, 2021
  9. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 3, 2021
  10. ghost locked as resolved and limited conversation to collaborators on Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions