コード例 #1
0
 /// <summary>
 /// Merge two MultiUnicodeAccessor objects.
 /// These cases are handled:
 ///		1. If an alternative exists in both objects, nothing is merged.
 ///		2. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
 ///		3. If the main object has an alternative, then do nothing.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="fConcatenateIfBoth"></param>
 /// <param name="sep">separator to use if concatenating</param>
 public void MergeAlternatives(IMultiStringAccessor source, bool fConcatenateIfBoth, string sep)
 {
     if (source == null)
     {
         return;                 // Nothing to do.
     }
     foreach (var lws in m_object.Services.WritingSystemManager.LocalWritingSystems)
     {
         var ws     = lws.Handle;
         var myAlt  = get_String(ws);
         var srcAlt = source.get_String(ws);
         if ((myAlt == null || myAlt.Length == 0) &&
             (srcAlt != null && srcAlt.Length != 0))
         {
             set_String(ws, srcAlt);
         }
         else if (!fConcatenateIfBoth)
         {
             continue;
         }
         else if (myAlt != null && myAlt.Length != 0 &&
                  srcAlt != null && srcAlt.Length != 0 &&
                  !myAlt.Equals(srcAlt))
         {
             var newBldr = m_object.Cache.TsStrFactory.GetIncBldr();
             newBldr.AppendTsString(get_String(ws));
             newBldr.Append(sep);
             newBldr.AppendTsString(source.get_String(ws));
             set_String(ws, newBldr.GetString());
         }
     }
 }
コード例 #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Appends all the alternatives from the source multi string to the alternatives of
 /// this here one.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="fPreventDuplication"><c>true</c> to avoid appending a string that is
 /// identical that matches the end of the existing string.</param>
 /// ------------------------------------------------------------------------------------
 public void AppendAlternatives(IMultiStringAccessor src, bool fPreventDuplication)
 {
     foreach (int ws in src.AvailableWritingSystemIds)
     {
         ITsString sourceStr = src.get_String(ws);
         if (sourceStr.Length == 0)
         {
             continue;
         }
         ITsString originalDest = get_String(ws);
         if (originalDest.Length == 0)
         {
             // There is no translation in the destination string, so just replace the
             // empty string with the source
             set_String(ws, sourceStr);
         }
         else
         {
             // There is existing translation in the destination string, so we need to merge
             // the translations. This should happen only for the first moved translation
             if (!originalDest.Text.EndsWith(sourceStr.Text, StringComparison.Ordinal))
             {
                 set_String(ws, originalDest.ConcatenateWithSpaceIfNeeded(sourceStr));
             }
         }
     }
 }
コード例 #3
0
ファイル: ExportUsfm.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Export the back translation of a picture caption
		/// </summary>
		/// <param name="caption">caption to export</param>
		/// ------------------------------------------------------------------------------------
		private void ExportPictureBT(IMultiStringAccessor caption)
		{
			string pictureMarker = GetMarkerForStyle(ScrStyleNames.Figure, @"\figcap");
			string marker = kBackTransMarkerPrefix + pictureMarker.Substring(1);

			for (int i = 0; i < m_requestedAnalWS.Length; i++)
			{
				int ws = m_requestedAnalWS[i];
				string captionText = caption.get_String(ws).Text;
				if (captionText != null && captionText != string.Empty)
				{
					// make sure the pic starts on a new line
					m_file.WriteLine();
					m_file.WriteLine(marker + GetIcuSuffix(i) + " " + captionText);
				}
			}
		}