Skip to content

Adding more StringSegment functionality - #230

Merged
Tratcher merged 1 commit into
devfrom
tratcher/segments
May 17, 2017
Merged

Adding more StringSegment functionality#230
Tratcher merged 1 commit into
devfrom
tratcher/segments

Conversation

@Tratcher

Copy link
Copy Markdown
Member

@Tratcher Tratcher added this to the 2.0.0-preview2 milestone May 16, 2017
@Tratcher Tratcher self-assigned this May 16, 2017
@Tratcher
Tratcher requested a review from JunTaoLuo May 16, 2017 23:10
}

// This handles StringSegment.Equals(string, StringSegment, StringComparison) and StringSegment.Equals(StringSegment, string, StringComparison)
// vai the implicit type converter

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

via

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just add an instance method Equals(string) to this? The implicit operator has marginal utility outside of this given that we use var typing everywhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implicit operator has been very useful in HttpAbstractions. I can convert all of the constructor and method parameters on my types to StringValues without breaking any callers or adding extra overloads.

StringSegment is easier to use when it can provide one-to-one replacements for existing string methods. Yes I could rewrite those call sites to .Equals(string), but this is quicker and cleaner.

}

// This handles StringSegment.Equals(string, StringSegment, StringComparison) and StringSegment.Equals(StringSegment, string, StringComparison)
// vai the implicit type converter

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just add an instance method Equals(string) to this? The implicit operator has marginal utility outside of this given that we use var typing everywhere.

{
/// <summary>
/// A <see cref="StringSegment"/> for a null <see cref="string"/>.
/// </summary>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default(StringSegment)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this is a strange one. Why do you need none?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more useful before I added the implicit string conversion. Removed.

@davidfowl

Copy link
Copy Markdown
Member

/cc @KrzysztofCwalina it's growing 😄

{
throw new IndexOutOfRangeException();
}
if (index - Offset >= Length)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !left.Equals(right);
}

// Do NOT add a implicit converter from StringSegment to String. That would negate most of the perf safety.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a // PERF:

/// <summary>
/// Creates a new <see cref="StringSegment"/> from the given <see cref="string"/>.
/// </summary>
/// <param name="value"></param>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc comment

/// <summary>
/// Retrieves a <see cref="StringSegment"/> that represents a substring from this <see cref="StringSegment"/>.
/// The <see cref="StringSegment"/> starts at the position specified by <paramref name="offset"/>.
/// </summary>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A substring of this instance of StringSegment that begins at offset? Doesn't sound right as it is now

@Tratcher
Tratcher force-pushed the tratcher/segments branch from ffc8148 to 6881708 Compare May 17, 2017 17:40
@Tratcher
Tratcher merged commit 6881708 into dev May 17, 2017
@Tratcher
Tratcher deleted the tratcher/segments branch May 17, 2017 17:41
natemcmaster pushed a commit that referenced this pull request Nov 5, 2018
@ghost ghost locked as resolved and limited conversation to collaborators May 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants