dotnet / dotnet/macios

NSAttributedString/NSMutableAttributedString missing substring constructors

Open
#5,523 3 comments 0 reactions 0 assignees View on GitHub
enhancement iOS macOS
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Currently, `NSString` APIs allow only to pass a managed string.

This forces APIs which would typically just use a substring be forced to allocate a string for the substring itself.

```
var myString = "asdf";
var myNSString = new NSAttributedString (myString.Subtring (0, 2));
```

Proposed APIs:
```
public NSAttributedString (string str, int start, int length) {}
public NSMutableAttributedString (string str, int start, int length) {}
... and a ton of over overloads
```

The implementation would then just marshal part of the string, avoiding an intermediate string allocation.

Via https://github.com/xamarin/xamarin-macios/pull/5517, a new `CreateNative (string, start, offset)` overload is introduced to allow creating a native string from a managed string slice.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.