From e07548d703798bfd661c1ab89cc3b48c936d0a77 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 4 Mar 2010 20:08:25 +0000 Subject: move linden notecard parsing from LSL_Api.cs to SLUtil so that region modules can use it --- OpenSim/Framework/SLUtil.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index 9d5c30a..ff5f8b9 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using OpenMetaverse; namespace OpenSim.Framework @@ -181,5 +182,101 @@ namespace OpenSim.Framework } #endregion SL / file extension / content-type conversions + + /// + /// Parse a notecard in Linden format to a string of ordinary text. + /// + /// + /// + public static string ParseNotecardToString(string rawInput) + { + return string.Join("\n", ParseNotecardToList(rawInput).ToArray()); + } + + /// + /// Parse a notecard in Linden format to a list of ordinary lines. + /// + /// + /// + public static List ParseNotecardToList(string rawInput) + { + string[] input = rawInput.Replace("\r", "").Split('\n'); + int idx = 0; + int level = 0; + List output = new List(); + string[] words; + + while (idx < input.Length) + { + if (input[idx] == "{") + { + level++; + idx++; + continue; + } + + if (input[idx]== "}") + { + level--; + idx++; + continue; + } + + switch (level) + { + case 0: + words = input[idx].Split(' '); // Linden text ver + // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard) + if (words.Length < 3) + return output; + + int version = int.Parse(words[3]); + if (version != 2) + return output; + break; + case 1: + words = input[idx].Split(' '); + if (words[0] == "LLEmbeddedItems") + break; + if (words[0] == "Text") + { + int len = int.Parse(words[2]); + idx++; + + int count = -1; + + while (count < len) + { + // int l = input[idx].Length; + string ln = input[idx]; + + int need = len-count-1; + if (ln.Length > need) + ln = ln.Substring(0, need); + + output.Add(ln); + count += ln.Length + 1; + idx++; + } + + return output; + } + break; + case 2: + words = input[idx].Split(' '); // count + if (words[0] == "count") + { + int c = int.Parse(words[1]); + if (c > 0) + return output; + break; + } + break; + } + idx++; + } + + return output; + } } -} +} \ No newline at end of file -- cgit v1.1 From e39fc95659a405a8500c9014d2ac31c5d85741d7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 5 Mar 2010 00:54:46 +0000 Subject: Fix LocalPresenceServiceConnector test now that the hardcoded test data has been removed from Data.Null.NullPresenceData Unfortunately, this meant publicly exposing the underlying service for the connector. The other solution would be to create alternative initializers for services and connectors where objects could be given directly rather than loaded indirectly through config. Unfortunately, this would require a lot of work in this case but might be the better way forward. --- OpenSim/Framework/SLUtil.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index ff5f8b9..81d82be 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -1,11 +1,15 @@ using System; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; namespace OpenSim.Framework { public static class SLUtil { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + #region SL / file extension / content-type conversions public static string SLAssetTypeToContentType(int assetType) @@ -190,7 +194,12 @@ namespace OpenSim.Framework /// public static string ParseNotecardToString(string rawInput) { - return string.Join("\n", ParseNotecardToList(rawInput).ToArray()); + string[] output = ParseNotecardToList(rawInput).ToArray(); + +// foreach (string line in output) +// m_log.DebugFormat("[PARSE NOTECARD]: ParseNotecardToString got line {0}", line); + + return string.Join("\n", output); } /// @@ -254,6 +263,7 @@ namespace OpenSim.Framework if (ln.Length > need) ln = ln.Substring(0, need); +// m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", ln); output.Add(ln); count += ln.Length + 1; idx++; -- cgit v1.1