Search
Active

14
Sign in to vote
1
Sign in to vote
Sign in
to vote
Type: Suggestion
ID: 413139
Opened: 2/9/2009 6:43:27 PM
Access Restriction: Public
0
Workaround(s)
1.StringInfo単位のLength命令

var str = “あいうえお”;
int sil = str.StringInfoLength;
var len = str.Length;

strが合成文字、サロゲートペアの場合silとlenは=にならない。
str.StringInfoLengthと書くことによって、StringInfo単位の長さを取得出来るようにして欲しいという要望です。

2.StringInfo単位のインデクサ

var str = “あいうえお”;
str.GetStringInfoCharacters[3]

strが合成文字、サロゲートペアを含む場合ただのインデクサとは=にならない。

3.IEnumerableの提供

var str = “あいうえお”;
from si in str.GetStringInfoEnumerable select si.String;

strが合成文字、サロゲートペアを含む場合だと結果が変わる

2番3番についてはstringのインデクサでcharにアクセス出来る(str[0]やforeach ( char x in str ) )ように、StringInfo単位としてアクセス出来るようにして欲しいという要望です。


4.StringInfoのEndsWithを提供して欲しい

var str = “あいうえお”;
StringInfo si = new StringInfo();
var se = str.EndsWith(si);

5.CharのEndsWithをpublicに変更して欲しい

str.EndsWith('あ’) を出来るようにして欲しい。

4番5番はstringのEndsWithメソッドの拡張と、公開です。string.EndsWithはstringを引数に取る物がありますが、CharやStringInfoを取る物がありません。
これらを追加していただいて後ろから文字列にアクセスするのが簡単にして欲しいという要望です。

5番を除いて新規追加であり、挙動の変更をお願いしている物ではありません。
Details (expand)
製品言語
日本語
バージョン
.NET Framework 2.0
オペレーティング システム
Windows Vista
オペレーティング システム言語
日本語
現状の問題点
StringInfoのサポートレベルが低くて利用しづらい
問題解決のための提案
StringのStringInfoへのサポートをあげることにより、多国語環境での実装を簡単にして欲しい
File Attachments
0 attachments
Sign in to post a comment.
Posted by NyaRuRu on 2/9/2009 at 8:05 PM
>Stringの不便なところを変更して欲しい
1, 2, 3 に関して希望する変更が書かれていないようですが,既存動作の変更を希望するということでしょうか?
Posted by M-now on 2/10/2009 at 4:29 AM
>NyaRuRuさん

var str = "あいうえお𦥑";
StringInfo sil = new StringInfo(str);

// 1)StringInfo単位のLength命令
var len = str.Length;
var slen = sil.LengthInTextElements;
Console.WriteLine("len=" + len + " slen=" + slen);

// str.StringInfoLength と書きたいという要望

// 2)StringInfo単位のインデクサ
Console.WriteLine(sil.SubstringByTextElements(5, 1));

// str.GetStringInfoCharacters[5] と書きたいという要望

// 3)IEnumerableの提供 (IEnumeratorはある)
var enumrator = StringInfo.GetTextElementEnumerator(str);
enumrator.Reset();
while(enumrator.MoveNext())
{
    Console.WriteLine(enumrator.Current);
}
Posted by NyaRuRu on 2/11/2009 at 5:57 PM
>M-nowさん

すみませんがコードだけ書かれても意味がよく分かりませんでした.

「リコンパイルで既存コードの意味が変わっても(良いので/良くないので),このように変更してほしい」という要望でないと評価しにくいです.
私自身は,リコンパイルで既存コードの意味が変わるような仕様変更はあまり賛成できません.
なので,具体的にどのような追加仕様/仕様変更を希望すると書いていただけた方がありがたいのですが,中さんの説明では具体的な点が省略されすぎていて,正直翻訳時に重要な部分が落ちてしまうのではないかと心配です.
Posted by NAKA Hirotoshi. on 2/11/2009 at 6:36 PM
1番についてはえムナウさんの指摘通り
str.StringInfoLengthと書くことによって、StringInfo単位の長さを取得出来るようにして欲しいという要望です。
2番3番についてはstringのインデクサでcharにアクセス出来る(str[0]やforeach ( char x in str ) )ように、StringInfo単位としてアクセス出来るようにして欲しいという要望です。
4番5番はstringのEndsWithメソッドの拡張と、公開です。string.EndsWithはstringを引数に取る物がありますが、CharやStringInfoを取る物がありません。
これらを追加していただいて後ろから文字列にアクセスするのが簡単にして欲しいという要望です。



Posted by Microsoft on 2/11/2009 at 6:37 PM
フィードバックをお送りいただきまして、ありがとうございます。いただいた報告内容に基づき、現在問題を調査中です。しばらくお待ちください。

Visual Studio Product Team

Problem Description:
1.Length in StringInfo

var str = “あいうえお”;
StringInfo sil = str.StringInfoLength;
var len = str.Length;

When str is composite characters or surrogate pair,
sil and len cannot be =.

2.Indexer in StringInfo

var str = “あいうえお”;
str.GetStringInfoCharacters[3]

When str includes composite characters or surrogate pair, it cannot be = to a regular indexer.


3.Providing IEnumerable

var str = “あいうえお”;
from si in str.GetStringInfoEnumerable select si.String;

When str includes composite characters or surrogate pair, the result changes.

4.Providing EndsWith in StringInfo is necessary.

var str = “あいうえお”;
StringInfo si = new StringInfo();
var se = str.EndsWith(si);

5.EndsWith in Char needs to change to public

str.EndsWith('あ’) needs to be enabled.

Problem Statement:
Supporting level of StringInfo is low and not easy-to-use.

Proposed Solution:
Enhancing support for StringInfo of String can make implementation in multilingual environment easier.



Posted by NAKA Hirotoshi. on 2/11/2009 at 6:39 PM
5番を除いて新規追加であり、挙動の変更をお願いしている物ではありません。

本文に追記しておきました。>Nyaruruさん
Posted by NyaRuRu on 2/13/2009 at 8:28 PM
>NAKA Hirotoshi.さん

なるほど,件名には「Stringの不便なところを変更して欲しい」とありますが,希望しているのは基本的に機能変更ではなくメンバの追加であるということですね.
説明中の string.StringInfoLength (プロパティ), string.GetStringInfoCharacters (プロパティ), string.GetStringInfoCharacters (プロパティ), string.GetStringInfoEnumerable (プロパティ) が,今回提案する新規メンバであることぐらいは書いておいて頂けると分かりやすかったです.

既に最初のバージョンで英訳されてしまっていますが,正直あの (英訳された) 文章を読んで何が欲しいのかちゃんと理解してくれるのか,かなり不安です.
# ついでに翻訳版では StringInfo sil = str.StringInfoLength; と間違って写されてたり.

ところで,プロパティに対して Get~ という名前の付け方は,(説明上の仮の名前であるにしても) 誤解されやすいのではないでしょうか?
それとも,これらのいくつかはメソッドを意図しており,書かれているサンプルコードの方が間違っているのでしょうか?
Posted by Microsoft on 3/15/2009 at 8:29 PM
Thank you for sending this valuable suggestion to improve the NETFX developer experience. Microsoft will look into this suggestion for the future releases. We belive that this suggestion will make the use of the StringInfo class easier. For the time being, our team is providing a code sample of how to workaround the lack of the suggested members of the class through the extension methods (http://msdn.microsoft.com/en-us/library/bb383977.aspx):


static class StringInfoOnStringExtensions

{

// 1. Length in StringInfo

public static int GetStringInfoLength(this string s)

{

StringInfo si = new StringInfo(s);

return si.LengthInTextElements;

}

// 2. Indexer in StringInfo

public static string GetStringInfoSubstringByTextElements(this string s, int i)

{

StringInfo si = new StringInfo(s);

return si.SubstringByTextElements(i);

}

// 3. Providing IEnumerable

public static IEnumerable<string> GetStringInfoEnumerable(this string s)

{

StringInfo si = new StringInfo(s);

int elements = si.LengthInTextElements;

for (int i = 0; i < elements; ++i)

{

yield return si.SubstringByTextElements(i,1);

}

}

// 4. Providing EndsWith in StringInfo is necessary.

public static bool EndsWith(this string s, StringInfo si)

{

return s.EndsWith(si.String);

}

public static bool EndsWith(this string s, StringInfo si, bool ignoreCase, CultureInfo ci)

{

return s.EndsWith(si.String, ignoreCase, ci);

}

public static bool EndsWith(this string s, StringInfo si, StringComparison comparisonType)

{

return s.EndsWith(si.String, comparisonType);

}

// 5. EndsWith in Char needs to change to public

public static bool EndsWith(this string s, char c)

{

return s.EndsWith(c.ToString());

}

public static void Bug607231()

{

string str = "";

Console.Out.WriteLine("StringInfo length: {0}", str.GetStringInfoLength());

Console.Out.WriteLine("String length: {0}", str.Length);

Console.Out.WriteLine("StringInfo substring: {0}", str.GetStringInfoSubstringByTextElements(3));

Console.Out.WriteLine("Enumerating over string with StringInfo:");

foreach (var s in str.GetStringInfoEnumerable())

{

Console.Out.WriteLine(s);

}

StringInfo si = new StringInfo("");

Console.Out.WriteLine("EndsWith stringInfo: {0}", str.EndsWith(si));

Console.Out.WriteLine("EndsWith char: {0}", str.EndsWith(''));

}

}



Posted by Microsoft on 3/16/2009 at 6:22 PM
NETFXデベロッパーエクスペリエンス向上に向けこちらの貴重なご提案ありがとうございます。
Microsoftではこちらのご提案を将来版のリリースに向けて検証してみる予定です。
私たちも、このご提案はStringInfoクラスをより使いやすいものにするものだと思います。
差し当たって、拡張メソッド(http://msdn.microsoft.com/en-us/library/bb383977.aspx 
翻訳者注:日本語ページはこちらになります。http://msdn.microsoft.com/en-us/library/bb383977.aspx)
を通じてクラスの推奨メンバーの不足をどのように回避するかというコードサンプルを提供させていただきます。

static class StringInfoOnStringExtensions

{

// 1. StringInfo単位のLength命令

public static int GetStringInfoLength(this string s)

{

StringInfo si = new StringInfo(s);

return si.LengthInTextElements;

}

// 2. StringInfo単位のインデクサ

public static string GetStringInfoSubstringByTextElements(this string s, int i)

{

StringInfo si = new StringInfo(s);

return si.SubstringByTextElements(i);

}

// 3. IEnumerableの提供

public static IEnumerable<string> GetStringInfoEnumerable(this string s)

{

StringInfo si = new StringInfo(s);

int elements = si.LengthInTextElements;

for (int i = 0; i < elements; ++i)

{

yield return si.SubstringByTextElements(i,1);

}

}

// 4. StringInfoのEndsWithを提供して欲しい

public static bool EndsWith(this string s, StringInfo si)

{

return s.EndsWith(si.String);

}

public static bool EndsWith(this string s, StringInfo si, bool ignoreCase, CultureInfo ci)

{

return s.EndsWith(si.String, ignoreCase, ci);

}

public static bool EndsWith(this string s, StringInfo si, StringComparison comparisonType)

{

return s.EndsWith(si.String, comparisonType);

}

// 5. CharのEndsWithをpublicに変更して欲しい

public static bool EndsWith(this string s, char c)

{

return s.EndsWith(c.ToString());

}

public static void Bug607231()

{

string str = "";

Console.Out.WriteLine("StringInfo length: {0}", str.GetStringInfoLength());

Console.Out.WriteLine("String length: {0}", str.Length);

Console.Out.WriteLine("StringInfo substring: {0}", str.GetStringInfoSubstringByTextElements(3));

Console.Out.WriteLine("Enumerating over string with StringInfo:");

foreach (var s in str.GetStringInfoEnumerable())

{

Console.Out.WriteLine(s);

}

StringInfo si = new StringInfo("");

Console.Out.WriteLine("EndsWith stringInfo: {0}", str.EndsWith(si));

Console.Out.WriteLine("EndsWith char: {0}", str.EndsWith(''));

}

}