示例#1
0
        /// <summary>
        /// Convert all AODL whitespace control character \ws3
        /// into their OpenDocument Xml textnodes
        /// </summary>
        /// <param name="text">The string to convert.</param>
        /// <returns>The parsed string</returns>
        public static string GetWhiteSpaceHtml(string text)
        {
            try
            {
                IList <WhiteSpaceHelper> matchList = new List <WhiteSpaceHelper>();
                const string             pat       =
                    "<text:s text:c=\"\\d+\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" />";
                Regex r = new Regex(pat, RegexOptions.IgnoreCase);
                Match m = r.Match(text);

                while (m.Success)
                {
                    Regex  r1   = new Regex(@"\d", RegexOptions.IgnoreCase);
                    Match  m1   = r1.Match(m.Value);
                    string html = "";

                    while (m1.Success)
                    {
                        int cnt = Convert.ToInt32(m1.Value);
                        for (int i = 0; i < cnt; i++)
                        {
                            html += "&nbsp;";
                        }
                        //Console.WriteLine(html);
                        break;
                    }
                    if (html.Length > 0)
                    {
                        WhiteSpaceHelper w = new WhiteSpaceHelper {
                            _value = html, _replacement = m.Value
                        };
                        matchList.Add(w);
                    }
                    m = m.NextMatch();
                }

                foreach (WhiteSpaceHelper ws in matchList)
                {
                    text = text.Replace(ws._replacement, ws._value);
                }
            }
            catch (Exception)
            {
                //unhandled, only whitespaces arent displayed correct
            }
            return(text);
        }
		/// <summary>
		/// Convert all AODL whitespace control character \ws3
		/// into their OpenDocument Xml textnodes
		/// </summary>
		/// <param name="text">The string to convert.</param>
		/// <returns>The parsed string</returns>
		public static string GetWhiteSpaceHtml(string text)
		{
			try
			{
				ArrayList matchList		= new ArrayList();
				string pat = @"<text:s text:c="+'"'.ToString()+@"\d+"+'"'.ToString()+" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" />";
				Regex r = new Regex(pat, RegexOptions.IgnoreCase);
				Match m = r.Match(text);

				while (m.Success) 
				{
					Regex r1			= new Regex(@"\d", RegexOptions.IgnoreCase);
					Match m1			= r1.Match(m.Value);
					string html			= "";

					while(m1.Success)
					{
						int cnt			= Convert.ToInt32(m1.Value);
						for(int i=0; i<cnt; i++)
							html			+= "&nbsp;";
						//Console.WriteLine(html);
						break;
					}
					if (html.Length > 0)
					{
						WhiteSpaceHelper w		= new WhiteSpaceHelper();
						w.Value				= html;
						w.Replacement		= m.Value;
						matchList.Add(w);
					}
					m = m.NextMatch();
				}
				
				foreach(WhiteSpaceHelper ws in matchList)
					text		= text.Replace(ws.Replacement, ws.Value);		
			}
			catch(Exception)
			{
				//unhandled, only whitespaces arent displayed correct
			}
			return text;
		}
		/// <summary>
		/// Convert all whitespace groups "    "
		/// into OpenDocument Xml textnodes
		/// </summary>
		/// <param name="stringToConvert">The string to convert.</param>
		/// <returns>The parsed string</returns>
		public static string GetWhiteSpaceXml(string stringToConvert)
		{
			try
			{
				ArrayList matchList		= new ArrayList();
				string pat = @"\s{2,}";
				Regex r = new Regex(pat, RegexOptions.IgnoreCase);
				Match m = r.Match(stringToConvert);

				while (m.Success) 
				{
					WhiteSpaceHelper w		= new WhiteSpaceHelper();
					for(int i=0; i<m.Length; i++)
						w.Value			+= " ";
					w.Replacement		= "<ws id=\""+m.Length.ToString()+"\"/>";//GetXmlWhiteSpace(m.Length);
					matchList.Add(w);
					m = m.NextMatch();
				}

				foreach(WhiteSpaceHelper w in matchList)
					stringToConvert		= stringToConvert.Replace(w.Value, w.Replacement);
				
			}
			catch(Exception)
			{
				//unhandled, only whitespaces arent displayed correct
			}
			return stringToConvert;
		}