Esempio n. 1
0
		/// <summary>
		/// Merge two MultiStringAccessor objects.
		/// These cases are handled:
		///		1. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
		///		2. If the main object has an alternative, and the source has none, then do nothing.
		///		3. If both alternatives are non-empty, then
		///			3.1 if fConcatenateIfBoth is false, keep the current value (do nothing)
		///			3.2 if fConcatenateIfBoth is true, and the values are equal, keep the current value (do nothing);
		///			3.3 if fConcatenateIfBoth is true, and the values are not equal, append the source to the current value.
		/// </summary>
		/// <param name="source"></param>
		/// <param name="fConcatenateIfBoth"></param>
		/// <param name="sep">insert between alterantives when merging.</param>
		public void MergeAlternatives(MultiStringAccessor source, bool fConcatenateIfBoth, string sep)
		{
			if (source == null)
				return; // Nothing to do.

			foreach (LgWritingSystem lws in m_cache.LanguageEncodings)
			{
				int ws = lws.Hvo;
				string myAlt = GetAlternative(ws).Text;
				string srcAlt = source.GetAlternative(ws).Text;
				if ((myAlt == null || myAlt == String.Empty)
					&& (srcAlt != null && srcAlt != String.Empty))
				{
					SetAlternative(source.GetAlternative(ws).UnderlyingTsString, ws);
				}
				else if (!fConcatenateIfBoth)
				{
					continue;
				}
				else if (myAlt != null && myAlt != String.Empty
					&& srcAlt != null && srcAlt != String.Empty
					&& !GetAlternative(ws).UnderlyingTsString.Equals(source.GetAlternative(ws).UnderlyingTsString))
				{
					// concatenate
					ITsStrBldr tsb = GetAlternative(ws).UnderlyingTsString.GetBldr();
					tsb.Replace(tsb.Length, tsb.Length, sep, null);
					tsb.ReplaceTsString(tsb.Length, tsb.Length, source.GetAlternative(ws).UnderlyingTsString);
					SetAlternative(tsb.GetString(), ws);
				}
			}
		}
Esempio n. 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Export the back translation of a picture caption
		/// </summary>
		/// <param name="caption">caption to export</param>
		/// ------------------------------------------------------------------------------------
		private void ExportPictureBT(MultiStringAccessor 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.GetAlternative(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);
				}
			}
		}