当前位置: 首页>>代码示例>>C#>>正文


C# ITsString.FetchRunInfoAt方法代码示例

本文整理汇总了C#中ITsString.FetchRunInfoAt方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.FetchRunInfoAt方法的具体用法?C# ITsString.FetchRunInfoAt怎么用?C# ITsString.FetchRunInfoAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITsString的用法示例。


在下文中一共展示了ITsString.FetchRunInfoAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindVerseNumberInTss

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Given a structured string, this method searches for a given target reference. If
		/// found, it returns the position just after the verse number found in that paragraph.
		/// If fStopIfGreaterVerseFound is true and we encounter a greater verse number,
		/// we return false but with information about the greater verse number encountered.
		/// </summary>
		/// <param name="targetRef">The reference being sought</param>
		/// <param name="tss">structured string to search for reference</param>
		/// <param name="fStopIfGreaterVerseFound">true if we want to return false immediately
		/// if we find a greater verse number</param>
		/// <param name="fChapterFound">at call: true if beginning of this tss is already in the
		/// target chapter; upon return: set to true if we encountered the target chapter in
		/// this tss</param>
		/// <param name="ichLim">The index immediately following the verse number found,
		/// or 0 if desired verse number not found.</param>
		/// <param name="startVerseOut">starting verse of the verse number run found,
		/// or 0 if desired verse number not found.</param>
		/// <param name="endVerseOut">ending verse of the verse number run found,
		/// or 0 if desired verse number not found.</param>
		/// <returns>true if matching verse number found, otherwise false</returns>
		/// <remarks>if fStopIfGreaterVerseFound is true and we in fact encounter a greater one,
		/// we return false immediately and the 3 output params provide info about the greater
		/// verse number found</remarks>
		/// ------------------------------------------------------------------------------------
		protected bool FindVerseNumberInTss(BCVRef targetRef, ITsString tss,
			bool fStopIfGreaterVerseFound, ref bool fChapterFound, out int ichLim,
			out int startVerseOut, out int endVerseOut)
		{
			ichLim = 0; // default values if not found
			startVerseOut = 0;
			endVerseOut = 0;

			if (tss.Text == null)
				return false;

			TsRunInfo tsi;
			ITsTextProps ttpRun;
			int ich = 0;
			bool fFoundChapterNumHere = false;
			int iRun = 0;
			while (ich < tss.Length)
			{
				// Get props of current run.
				ttpRun = tss.FetchRunInfoAt(ich, out tsi);
				// If we are already in our target chapter
				if (fChapterFound)
				{
					// See if run is our verse number style.
					if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
					{
						// The whole run is the verse number. Extract it.
						string sVerseNum = tss.get_RunText(tsi.irun);
						int startVerse, endVerse;
						ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
						if (startVerse <= targetRef.Verse && endVerse >= targetRef.Verse)
						{
							ichLim = tsi.ichLim; //end of the verse number run
							startVerseOut = startVerse;
							endVerseOut = endVerse;
							return true;
						}
						else if (fStopIfGreaterVerseFound && startVerse > targetRef.Verse)
						{	// we found a greater verse number and we want to stop on it
							ichLim = tsi.ichLim; //end of the verse number run
							startVerseOut = startVerse;
							endVerseOut = endVerse;
							return false;
						}
					}
					else if (targetRef.Verse == 1 && fFoundChapterNumHere)
					{
						ichLim = tsi.ichMin; //end of the verse number run
						startVerseOut = endVerseOut = 1;
						return true;
					}
				}

				// See if run is our chapter number style.
				if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
				{
					try
					{
						// Assume the whole run is the chapter number. Extract it.
						string sChapterNum = tss.get_RunText(tsi.irun);
						int nChapter = ScrReference.ChapterToInt(sChapterNum);
						// Is this our target chapter number?
						fFoundChapterNumHere = fChapterFound =
							(nChapter == targetRef.Chapter || fChapterFound);
					}
					catch (ArgumentException)
					{
						// ignore runs with invalid Chapter numbers
					}
				}
				ich = tsi.ichLim;
				iRun++;
			}

			// Verse was not found in the tss
//.........这里部分代码省略.........
开发者ID:sillsdev,项目名称:WorldPad,代码行数:101,代码来源:TeEditingHelper.cs

示例2: GetNextVerseNumberRun

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the text of the next verse number run in a given ITsString after the given
		/// character position.
		/// </summary>
		/// <param name="tss">the given ITsString</param>
		/// <param name="ich">the given character position</param>
		/// <param name="sChapterNumberRun">the string of a chapter number run,
		/// if one was found just before the verse number we found; else null</param>
		/// <returns>the string of the next verse number after the given ich, or null if not
		/// found</returns>
		/// ------------------------------------------------------------------------------------
		private string GetNextVerseNumberRun(ITsString tss, int ich,
			out string sChapterNumberRun)
		{
			sChapterNumberRun = null;

			if (tss.Text == null)
				return null;

			TsRunInfo tsi;
			ITsTextProps ttpRun;
			while (ich < tss.Length)
			{
				// Get props of current run.
				ttpRun = tss.FetchRunInfoAt(ich, out tsi);
				// See if run is our verse number style.
				if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
				{
					// The whole run is the verse number. Extract it.
					string sVerseNumberRun = tss.get_RunText(tsi.irun);

					// Also extract a preceeding chapter number run, if present.
					if (tsi.ichMin > 0)
					{
						// Get props of previous run.
						ttpRun = tss.FetchRunInfoAt(tsi.ichMin - 1, out tsi);
						// See if run is chapter number style; get its text.
						if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
							sChapterNumberRun = tss.get_RunText(tsi.irun);
					}
					return sVerseNumberRun;
				}

				// if this is a chapter number, check the next run to see if it is a
				// verse number (perhaps it is implied).
				if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber) &&
					tsi.irun < tss.RunCount - 1)
				{
					ITsTextProps ttpNextRun = tss.get_Properties(tsi.irun + 1);
					if (!StStyle.IsStyle(ttpNextRun, ScrStyleNames.VerseNumber))
					{
						// verse 1 is implied; get the chapter number
						sChapterNumberRun = tss.get_RunText(tsi.irun);
						return null;
					}
				}

				ich = tsi.ichLim; // get ready for next run
			}

			// no verse number found
			return null;
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:64,代码来源:TeEditingHelper.cs

示例3: GetBCVRefAtPosWithinTss

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the start and end reference, by searching backwards in the given ITsString
		/// from the given position.
		/// </summary>
		/// <param name="tss">the given ITsString</param>
		/// <param name="ichPos">Index of character in paragraph whose reference we want</param>
		/// <param name="fAssocPrev">Consider this position to be associated with any preceding
		/// text in the paragraph (in the case where ichPos is at a chapter boundary).</param>
		/// <param name="refStart">[out] Start reference for the paragraph.</param>
		/// <param name="refEnd">[out] End reference for the paragraph.</param>
		/// <returns>A value of <see cref="ChapterVerseFound"/> that tells if a chapter and/or
		/// verse number was found in this paragraph.</returns>
		/// <remarks>If ichPos LT zero, we will not search this para, and simply return.
		/// Be careful not to use this method to search the contents of paragraph using
		/// character offsets from the BT!
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		static public ChapterVerseFound GetBCVRefAtPosWithinTss(ITsString tss, int ichPos,
			bool fAssocPrev, out BCVRef refStart, out BCVRef refEnd)
		{
			refStart = new BCVRef();
			refEnd = new BCVRef();
			ChapterVerseFound retVal = ChapterVerseFound.None;

			if (tss.Length <= 0)
				return retVal;

			TsRunInfo tsi;
			ITsTextProps ttpRun;
			bool fGotVerse = false;

			int ich = ichPos;
			if (ich > tss.Length)
				ich = tss.Length;
			while (ich >= 0)
			{
				// Get props of current run.
				ttpRun = tss.FetchRunInfoAt(ich, out tsi);

				// If we're at (the front edge of) a C/V number boundary and the
				// caller said to associate the position with the previous material, then
				// ignore this run unless we're at the beginning of the para.
				// The run is actually the *following*  run, which we don't care about.
				if (!fAssocPrev || ichPos <= 0 || ichPos != tsi.ichMin)
				{
					// See if it is our verse number style.
					if (!fGotVerse && StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
					{
						// The whole run is the verse number. Extract it.
						string sVerseNum = tss.get_RunText(tsi.irun);
						//					string sVerseNum = tss.Text.Substring(tsi.ichMin,
						//						tsi.ichLim - tsi.ichMin);
						int startVerse, endVerse;
						ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
						refStart.Verse = startVerse;
						refEnd.Verse = endVerse;
						fGotVerse = true;
						retVal = ChapterVerseFound.Verse;
					}
					// See if it is our chapter number style.
					else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
					{
						try
						{
							// Assume the whole run is the chapter number. Extract it.
							string sChapterNum = tss.get_RunText(tsi.irun);
							int nChapter = ScrReference.ChapterToInt(sChapterNum);
							refStart.Chapter = refEnd.Chapter = nChapter;

							if (fGotVerse)
							{
								// Found a chapter number to go with the verse number we
								// already found, so build the full reference using this
								// chapter with the previously found verse (already set).
								retVal |= ChapterVerseFound.Chapter;
							}
							else
							{
								// Found a chapter number but no verse number, so assume the
								// edited text is in verse 1 of the chapter.
								refStart.Verse = refEnd.Verse = 1;
								fGotVerse = true;
								retVal = ChapterVerseFound.Chapter | ChapterVerseFound.Verse;
							}
							break;
						}
						catch (ArgumentException)
						{
							// ignore runs with invalid Chapter numbers
						}
					}
				}

				// move index (going backwards) to the character just before the Min of the run
				// we just looked at
				ich = tsi.ichMin - 1;
			}
			return retVal;
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:100,代码来源:ScrTxtPara.cs


注:本文中的ITsString.FetchRunInfoAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。