|
using System;
using System.Collections.Generic;
using NBidi;
namespace NBiDi.Extensions
{
public static class NBiDiExtensions
{
public static bool IsTextNeedAlignToRight(string TextToCheckIfNeedsRTL)
{
for (int i = 0; i < TextToCheckIfNeedsRTL.Length; i++)
{
if (IsRTLChar(TextToCheckIfNeedsRTL[i]))
return true;
if (IsLTRChar(TextToCheckIfNeedsRTL[i]))
return false;
}
return false;
}
public static bool IsRTLChar(char charToCheck)
{
BidiCharacterType curBidiCharTypeToCheckIfRTLorLTR =
BidiCharacterTypeResolver.GetBidiCharacterType(charToCheck);
return (IsBidiCharTypeRTL(curBidiCharTypeToCheckIfRTLorLTR));
}
public static bool IsLTRChar(char charToCheck)
{
BidiCharacterType curBidiCharTypeToCheckIfRTLorLTR =
BidiCharacterTypeResolver.GetBidiCharacterType(charToCheck);
return (IsBidiCharTypeLTR(curBidiCharTypeToCheckIfRTLorLTR));
}
private static bool IsBidiCharTypeLTR(BidiCharacterType curBidiCharTypeToCheckIfRTLorLTR)
{
return (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.L)
|| (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.LRE)
|| (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.LRO);
}
private static bool IsBidiCharTypeRTL(BidiCharacterType curBidiCharTypeToCheckIfRTLorLTR)
{
return (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.R)
|| (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.RLE)
|| (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.AL)
|| (curBidiCharTypeToCheckIfRTLorLTR == BidiCharacterType.RLO);
}
public static bool IsSpacerCharcter(char charcterToCheck)
{
return (IsWhitespace(charcterToCheck)
|| IsPunctionChar(charcterToCheck));
}
public static bool IsPunctionChar(char charcterToCheck)
{
BidiCharacterType curBidiCharTypeToCheckIfWhitespace =
BidiCharacterTypeResolver.GetBidiCharacterType(charcterToCheck);
return (curBidiCharTypeToCheckIfWhitespace == BidiCharacterType.CS);
// return Char.IsPunctuation(charcterToCheck);
}
public static bool IsWhitespace(char charcterToCheck)
{
BidiCharacterType curBidiCharTypeToCheckIfWhitespace =
BidiCharacterTypeResolver.GetBidiCharacterType(charcterToCheck);
return ((curBidiCharTypeToCheckIfWhitespace == BidiCharacterType.WS)
|| (curBidiCharTypeToCheckIfWhitespace == BidiCharacterType.B)
|| (curBidiCharTypeToCheckIfWhitespace == BidiCharacterType.S)
|| (curBidiCharTypeToCheckIfWhitespace == BidiCharacterType.ON))
;
}
public static bool IsNumberCharcter(char charToCheck)
{
return Char.IsDigit(charToCheck);
}
public static string[] SplitToParagraphs(string StringToSplit)
{
string[] ReturnValues = StringToSplit.Split('\u000A', '\u000D', '\u001C', '\u001E', '\u0085', '\u2029',
/*Used by blend for breaklines */ '\u2028');
return ReturnValues;
}
public static char GetLTRorRTLStarterCharcterForLine(bool RTL)
{
if (RTL)
return RTLFirstCharMark;
else
return LTRFirstCharMark;
}
public static char LTRFirstCharMark
{
get
{
return NBidi.BidiChars.LRE;
}
}
public static char RTLFirstCharMark
{
get
{
return NBidi.BidiChars.RLE;
}
}
public static bool? GetLTRorRTLStarterCharcterForLineFromLastCharToFirst(string TextToCheckIfNeedsRTL)
{
for (int i = TextToCheckIfNeedsRTL.Length - 1; i >= 0; i--)
{
if (IsRTLChar(TextToCheckIfNeedsRTL[i]))
return true;
if (IsLTRChar(TextToCheckIfNeedsRTL[i]))
return false;
}
return null;
}
public static string ReverseStringByWhiteSpaceForNumbersOnly(string stringToReverseByWhitespaces)
{
char[] whiteSpaceChars =
new char[] {'\u000C', '\u0020', '\u1680', '\u180E', '\u2000', '\u200A', '\u2028', '\u205F', '\u3000'};
List<string> seperatedWords = new List<string>(stringToReverseByWhitespaces.Split(whiteSpaceChars));
seperatedWords.Reverse();
return String.Join("\u000C", seperatedWords.ToArray());
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Justin-Josef Angel is a C# Microsoft Most Valuable professional, a Senior .Net consultant in Israel with 4 years of .Net experience and has 8 years of Web experience.
Justin's been working this past year on two Enterprise sized Silverlight projects with his customers. During that time he's gained a real-insight into Silverlight's inner workings and how to integrate Silverlight into the real world of software development. Additionally, During that time he's developed a few well-known projects like the "Silverlight 1.0 Javascript Intellisense", "Silverlight 1.1 Hebrew & Arabic Languages support" and a few others you might know.
Justin is also a seasoned presenter with an impressive track-record of talking in front of thousands of people in Israel.
Justin owns the first .Net blog written in Hebrew -
http://www.JustinAngel.Net .
And he also owns an additional blog with mixed Hebrew & English content -
http://blogs.Microsoft.co.il/blogs/JustinAngel.
A full list of his articles (all 100+ of them) can be found at:
http://www.JustinAngel.Net/#index