本文整理汇总了C#中ITsString.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.GetChars方法的具体用法?C# ITsString.GetChars怎么用?C# ITsString.GetChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITsString
的用法示例。
在下文中一共展示了ITsString.GetChars方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpellCheckProps
/// ------------------------------------------------------------------------------------
/// <summary>
/// Answer the spelling status of the indicated character in the string, unless it is an
/// ORC, in which case, for each ORC we answer a different value (that is not any of the
/// valid spelling statuses).
/// Enhance JohnT: we don't want to consider embedded-picture ORCs to count as
/// different; we may strip them out before we start checking the word.
/// </summary>
/// ------------------------------------------------------------------------------------
int SpellCheckProps(ITsString tss, int ich, IVwStylesheet styles)
{
// For our purposes here, ORC (0xfffc) is considered to have a different spelling status from everything else,
// even from every other ORC in the string. This means we always offer to insert spaces adjacent to them.
if (ich < tss.Length && tss.GetChars(ich, ich + 1)[0] == 0xfffc)
{
return -50 - ich;
}
ITsTextProps props = tss.get_PropertiesAt(ich);
string style = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
int var, val;
if (styles != null && !string.IsNullOrEmpty(style))
{
ITsTextProps styleProps = styles.GetStyleRgch(style.Length, style);
if (styleProps != null)
{
val = styleProps.GetIntPropValues((int)FwTextPropType.ktptSpellCheck, out var);
if (var != -1)
return val; // style overrides
}
}
val = props.GetIntPropValues((int)FwTextPropType.ktptSpellCheck, out var);
if (var == -1)
return 0; // treat unspecified the same as default.
else
return val;
}
示例2: MakeEmbeddedNscSuggestion
private IList<SpellCorrectMenuItem> MakeEmbeddedNscSuggestion(ref ITsString tssWord, IVwStylesheet styles, IVwRootBox rootb,
int hvoObj, int tag, int wsAlt, int ichMin, int ichLim, out ITsString tssKeepOrcs)
{
List<SpellCorrectMenuItem> result = new List<SpellCorrectMenuItem>();
// Make an item with inserted spaces.
ITsStrBldr bldr = tssWord.GetBldr();
int spCur = SpellCheckProps(tssWord, 0, styles);
int offset = 0;
bool foundDiff = false;
bool fHasOrc = false;
ITsStrBldr bldrWord = null;
ITsStrBldr bldrKeepOrcs = null;
int bldrWordOffset = 0;
// Start at 0 even though we already got its props, because it just might be an ORC.
for (int ich = 0; ich < tssWord.Length; ich++)
{
if (tssWord.GetChars(ich, ich + 1) == "\xfffc")
{
ITsTextProps ttp = tssWord.get_PropertiesAt(ich);
string objData = ttp.GetStrPropValue((int)FwTextPropType.ktptObjData);
if (objData.Length == 0 || objData[0] != Convert.ToChar((int)FwObjDataTypes.kodtGuidMoveableObjDisp))
{
fHasOrc = true;
int ichInsert = ich + offset;
bldr.Replace(ichInsert, ichInsert, " ", null);
spCur = -50 - ich; // Same trick as SpellCheckProps to ensure won't match anything following.
offset++;
foundDiff = true;
}
else
{
// An ORC we want to ignore, but not lose. We will strip it out of the word we will
// actually spell-check if we don't find other ORC problems, but save it to be
// inserted at the end of any correction word. We might still use
// our own "insert missing spaces" option, too, if we find another ORC of a different type.
// In that case, this ORC just stays as part of the string, without spaces inserted.
if (bldrWord == null)
{
bldrWord = tssWord.GetBldr();
bldrKeepOrcs = TsStrBldrClass.Create();
}
bldrWord.Replace(ich - bldrWordOffset, ich - bldrWordOffset + 1, "", null);
bldrKeepOrcs.Replace(bldrKeepOrcs.Length, bldrKeepOrcs.Length, "\xfffc", ttp);
bldrWordOffset++;
}
}
else // not an orc, see if props changed.
{
int spNew = SpellCheckProps(tssWord, ich, styles);
if (spNew != spCur)
{
int ichInsert = ich + offset;
bldr.Replace(ichInsert, ichInsert, " ", null);
spCur = spNew;
offset++;
foundDiff = true;
}
}
}
if (bldrWord != null)
{
tssWord = bldrWord.GetString();
tssKeepOrcs = bldrKeepOrcs.GetString();
}
else
{
tssKeepOrcs = null;
}
if (!foundDiff)
return result;
ITsString suggest = bldr.GetString();
// There might still be an ORC in the string, in the pathological case of a picture anchor and embedded verse number
// in the same word(!). Leave it in the replacement, but not in the menu item.
string menuItemText = suggest.Text.Replace("\xfffc", "");
if (fHasOrc)
menuItemText = RootSiteStrings.ksInsertMissingSpaces;
result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, menuItemText, suggest));
return result;
}
示例3: AnalysisAdjuster
/// <summary>
/// Make one for adjusting the specified paragraph to its current contents from the specified
/// old contents
/// </summary>
private AnalysisAdjuster(IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo)
{
m_para = para;
m_oldContents = oldContents;
m_newContents = m_para.Contents;
m_changedFontOnly = false;
if(diffInfo != null && ( diffInfo.IchFirstDiff != 0 || diffInfo.CchDeleteFromOld != diffInfo.CchInsert ||
m_oldContents == null || m_newContents == null || m_oldContents.Length == 0 ||
!m_oldContents.GetChars(0, m_oldContents.Length).Equals(m_newContents.GetChars(0, m_newContents.Length))))
{
m_paraDiffInfo = diffInfo;
}
else
{
//We didn't really change it, maybe the ws changed, but all the characters are identical
//let's let the user keep their analysis
m_paraDiffInfo = new TsStringDiffInfo(0, 0, 0);
m_changedFontOnly = true; // a flag to let later adjustment ops remember this
}
}
示例4: ReplaceRangeInBt
/// ------------------------------------------------------------------------------------
/// <summary>
/// Insert/replace the range in the given back translation with the given chapter and verse.
/// </summary>
/// <param name="hvoObj">The id of the translation being modified</param>
/// <param name="propTag">The flid (i.e. Translation)</param>
/// <param name="wsAlt">The writing system of the back translation multiString alt</param>
/// <param name="ichMin">character offset Min at which we will replace in the tss
/// </param>
/// <param name="ichLim">end of the range at which we will replace in the tss </param>
/// <param name="sChapterNumIns">The chapter number string to be inserted, if any</param>
/// <param name="sVerseNumIns">The verse number string to be inserted, if any</param>
/// <param name="tssBt">ref: The given structured string from the BT, in which we will
/// replace</param>
/// <param name="ichLimIns">output: gets set to the end of what we inserted</param>
/// ------------------------------------------------------------------------------------
private void ReplaceRangeInBt(int hvoObj, int propTag, int wsAlt, int ichMin, int ichLim,
ref string sChapterNumIns, ref string sVerseNumIns, ref ITsString tssBt, out int ichLimIns)
{
ichLimIns = -1;
// Insert the chapter number, if defined
if (sChapterNumIns != null)
{
string oldText = tssBt.get_RunText(tssBt.get_RunAt(ichMin));
ITsTextProps oldProps = tssBt.get_PropertiesAt(ichMin);
if (oldText == sChapterNumIns && oldProps.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle) == ScrStyleNames.ChapterNumber)
{
ichMin += sChapterNumIns.Length;
sChapterNumIns = null;
}
else
{
ITsTextProps ttpChap = StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, wsAlt);
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, sChapterNumIns, ttpChap, ichMin, ichLim,
ref tssBt, out ichLimIns);
// adjust range for verse insert
ichMin += sChapterNumIns.Length;
ichLim = ichMin;
}
}
// Insert the verse number, if defined. If the text has not changed, then do not make
// the change so an undo task will not be created.
if (sVerseNumIns != null)
{
string oldText = tssBt.GetChars(ichMin, ichLim);
ITsTextProps oldProps = tssBt.get_PropertiesAt(ichMin);
if (oldText == sVerseNumIns && oldProps.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle) == ScrStyleNames.VerseNumber)
sVerseNumIns = null;
else
{
ITsTextProps ttpVerse = StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, wsAlt);
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, sVerseNumIns, ttpVerse,
ichMin, ichLim, ref tssBt, out ichLimIns);
}
}
}
示例5: HasLabelText
/// <summary>
/// Test whether a run of text in a TsString contains 'label' text which should cause a segment break.
/// (Current definition is that there are characters in the range with the Scripture styles VerseNumber
/// or ChapterNumber, or the range being tested is a single character (possibly part of a longer run)
/// which is a hard line break.
/// </summary>
internal static bool HasLabelText(ITsString tss, int ichMin, int ichLim)
{
// True if the run at ichMin has one of the interesting styles or is an ORC.
int irun = tss.get_RunAt(ichMin);
if (IsLabelText(tss, irun, false))
return true;
// See if any later run in the character range has the required style or is an ORC.
int crun = tss.RunCount;
for (irun++; irun < crun && tss.get_MinOfRun(irun) < ichLim; irun++)
{
if (IsLabelText(tss, irun, false))
return true;
}
// All other ways it might be treated as a label have failed, so return false
// unless it is a one-character range containing a hard line break.
if (ichLim == ichMin + 1)
return tss.GetChars(ichMin, ichLim) == StringUtils.kChHardLB.ToString();
return false;
}
示例6: LastCharIsSpaceOrQuote
private static bool LastCharIsSpaceOrQuote(ITsString wordString, int index, char space, char quote)
{
index -= 1;
if (index < 0)
return false;
var charString = wordString.GetChars(index, index + 1);
return (charString[0] == space || charString[0] == quote);
}
示例7: AppendWithOptionalSpace
/// <summary>
/// Append tssApp to the builder. If both are non-empty and there is no white space
/// at the end of bldr or the start of tssApp, also add a space.
/// </summary>
/// <param name="bldr"></param>
/// <param name="tssApp"></param>
private void AppendWithOptionalSpace(ITsStrBldr bldr, ITsString tssApp)
{
if (tssApp.Length == 0)
return;
// Insert a space if needed.
if (bldr.Length > 0)
{
string lastChar = bldr.GetChars(bldr.Length - 1, bldr.Length);
if (!IsWhite(lastChar[0]))
{
// No space at end of builder...check start of stuff to append
string firstChar = tssApp.GetChars(0, 1);
if(!IsWhite(firstChar[0]))
{
bldr.Replace(bldr.Length, bldr.Length, " ", null);
}
}
}
bldr.ReplaceTsString(bldr.Length, bldr.Length, tssApp);
}
示例8: EndsWithNonSpace
/// <summary>
/// True if the string ends with a non-space (and so needs a space inserted after it).
/// </summary>
/// <param name="tssFt"></param>
/// <returns></returns>
private static bool EndsWithNonSpace(ITsString tssFt)
{
int length = tssFt.Length;
if (length == 0)
return true;
return tssFt.GetChars(length - 1, length) != " ";
}
示例9: StartsWithSpaceOrOrc
/// <summary>
/// True if a string starts with a space or ORC and so does not require a space inserted before it.
/// (Also if it is empty...don't need to put a space if we aren't going to put something after it.)
/// </summary>
/// <param name="tssFt"></param>
/// <returns></returns>
private static bool StartsWithSpaceOrOrc(ITsString tssFt)
{
if (tssFt.Length == 0)
return true;
char first = tssFt.GetChars(0, 1)[0];
return first == StringUtils.kchObject || first == ' ';
}