コード例 #1
0
        /// <summary>
        /// Crawls all runs in the specified string. The run modifier is called for each run in the
        /// specified string. If the run modifier returns <c>null</c>, the run is removed from
        /// the string. If all runs are removed, this method returns <c>null</c>.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="runModifier">The run modifier.</param>
        /// <returns></returns>
        public static ITsString CrawlRuns(ITsString str, Func <ITsString, ITsString> runModifier)
        {
            ITsIncStrBldr tisb     = TsIncStrBldrClass.Create();
            bool          modified = false;
            bool          empty    = true;

            for (int i = 0; i < str.RunCount; i++)
            {
                int ichMin, ichLim;
                str.GetBoundsOfRun(i, out ichMin, out ichLim);
                ITsString oldRun = str.GetSubstring(ichMin, ichLim);
                ITsString newRun = runModifier(oldRun);
                if (newRun != null)
                {
                    if (modified || newRun != oldRun)
                    {
                        tisb.AppendTsString(newRun);
                        modified = true;
                    }
                    empty = false;
                }
                else
                {
                    modified = true;
                }
            }

            if (empty)
            {
                return(null);
            }

            return(modified ? tisb.GetString() : str);
        }
コード例 #2
0
        private void VerifyObjData(ITsString tss, int ichMin, int ichLim, string newPath)
        {
            var objData = tss.get_StringPropertyAt(ichMin, (int)FwTextPropType.ktptObjData);

            Assert.That(objData, Is.Not.Null);
            Assert.That(objData.Length, Is.GreaterThan(1));
            Assert.That(objData[0], Is.EqualTo(Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName)));
            Assert.That(objData.Substring(1), Is.EqualTo(newPath));
            int ichMinActual, ichLimActual;

            tss.GetBoundsOfRun(tss.get_RunAt(ichMin), out ichMinActual, out ichLimActual);
            Assert.That(ichLimActual, Is.EqualTo(ichLim));
        }
コード例 #3
0
ファイル: FdoScripture.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Return a TsString in which any CV numbers have been replaced by their BT equivalents
		/// (in the specified writing system). Other properties, including style, are copied
		/// from the input numbers.
		/// </summary>
		/// <param name="input">The input.</param>
		/// <param name="wsTrans">The ws trans.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ITsString ConvertCVNumbersInStringForBT(ITsString input, int wsTrans)
		{
			ITsStrBldr bldr = null;
			// reverse order so we don't mess up offsets if new numbers differ in length.
			for (int iRun = input.RunCount - 1; iRun >= 0; iRun--)
			{
				string styleName = input.get_Properties(iRun).GetStrPropValue(
					(int)FwTextPropType.ktptNamedStyle);

				if (styleName == ScrStyleNames.ChapterNumber ||
					styleName == ScrStyleNames.VerseNumber)
				{
					string number = ConvertVerseChapterNumForBT(input.get_RunText(iRun));
					if (number == null)
						continue; // pathologically an empty string has verse number style??
					if (bldr == null)
						bldr = input.GetBldr(); // we have an actual change.
					int ichMin, ichLim;
					input.GetBoundsOfRun(iRun, out ichMin, out ichLim);
					bldr.SetIntPropValues(ichMin, ichLim, (int)FwTextPropType.ktptWs,
						(int)FwTextPropVar.ktpvDefault, wsTrans);
					bldr.Replace(ichMin, ichLim, number, null);
				}
			}
			if (bldr != null)
				return bldr.GetString();
			return input;
		}
コード例 #4
0
ファイル: StringServices.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Crawls all runs in the specified string. The run modifier is called for each run in the
		/// specified string. If the run modifier returns <c>null</c>, the run is removed from
		/// the string. If all runs are removed, this method returns <c>null</c>.
		/// </summary>
		/// <param name="str">The string.</param>
		/// <param name="runModifier">The run modifier.</param>
		/// <returns></returns>
		public static ITsString CrawlRuns(ITsString str, Func<ITsString, ITsString> runModifier)
		{
			ITsIncStrBldr tisb = TsIncStrBldrClass.Create();
			bool modified = false;
			bool empty = true;
			for (int i = 0; i < str.RunCount; i++)
			{
				int ichMin, ichLim;
				str.GetBoundsOfRun(i, out ichMin, out ichLim);
				var oldRun = str.GetSubstring(ichMin, ichLim);
				var newRun = runModifier(oldRun);
				modified = modified || newRun != oldRun;
				if (newRun != null)
				{
					tisb.AppendTsString(newRun);
					empty = false;
				}
			}

			if (empty)
				return null;

			return modified ? tisb.GetString() : str;
		}
コード例 #5
0
		private void VerifyObjData(ITsString tss, int ichMin, int ichLim, string newPath)
		{
			var objData = tss.get_StringPropertyAt(ichMin, (int)FwTextPropType.ktptObjData);
			Assert.That(objData, Is.Not.Null);
			Assert.That(objData.Length, Is.GreaterThan(1));
			Assert.That(objData[0], Is.EqualTo(Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName)));
			Assert.That(objData.Substring(1), Is.EqualTo(newPath));
			int ichMinActual, ichLimActual;
			tss.GetBoundsOfRun(tss.get_RunAt(ichMin), out ichMinActual, out ichLimActual);
			Assert.That(ichLimActual, Is.EqualTo(ichLim));
		}