aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/SLUtil.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-03-04 20:08:25 +0000
committerJustin Clark-Casey (justincc)2010-03-04 20:08:25 +0000
commite07548d703798bfd661c1ab89cc3b48c936d0a77 (patch)
tree90f23640fda71f2b74a181df9cadf56cdabc4b41 /OpenSim/Framework/SLUtil.cs
parentcompiler warnings revealed that public PlaySoundSlavePrims properties were ch... (diff)
downloadopensim-SC_OLD-e07548d703798bfd661c1ab89cc3b48c936d0a77.zip
opensim-SC_OLD-e07548d703798bfd661c1ab89cc3b48c936d0a77.tar.gz
opensim-SC_OLD-e07548d703798bfd661c1ab89cc3b48c936d0a77.tar.bz2
opensim-SC_OLD-e07548d703798bfd661c1ab89cc3b48c936d0a77.tar.xz
move linden notecard parsing from LSL_Api.cs to SLUtil so that region modules can use it
Diffstat (limited to 'OpenSim/Framework/SLUtil.cs')
-rw-r--r--OpenSim/Framework/SLUtil.cs99
1 files changed, 98 insertions, 1 deletions
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 @@
1using System; 1using System;
2using System.Collections.Generic;
2using OpenMetaverse; 3using OpenMetaverse;
3 4
4namespace OpenSim.Framework 5namespace OpenSim.Framework
@@ -181,5 +182,101 @@ namespace OpenSim.Framework
181 } 182 }
182 183
183 #endregion SL / file extension / content-type conversions 184 #endregion SL / file extension / content-type conversions
185
186 /// <summary>
187 /// Parse a notecard in Linden format to a string of ordinary text.
188 /// </summary>
189 /// <param name="rawInput"></param>
190 /// <returns></returns>
191 public static string ParseNotecardToString(string rawInput)
192 {
193 return string.Join("\n", ParseNotecardToList(rawInput).ToArray());
194 }
195
196 /// <summary>
197 /// Parse a notecard in Linden format to a list of ordinary lines.
198 /// </summary>
199 /// <param name="rawInput"></param>
200 /// <returns></returns>
201 public static List<string> ParseNotecardToList(string rawInput)
202 {
203 string[] input = rawInput.Replace("\r", "").Split('\n');
204 int idx = 0;
205 int level = 0;
206 List<string> output = new List<string>();
207 string[] words;
208
209 while (idx < input.Length)
210 {
211 if (input[idx] == "{")
212 {
213 level++;
214 idx++;
215 continue;
216 }
217
218 if (input[idx]== "}")
219 {
220 level--;
221 idx++;
222 continue;
223 }
224
225 switch (level)
226 {
227 case 0:
228 words = input[idx].Split(' '); // Linden text ver
229 // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard)
230 if (words.Length < 3)
231 return output;
232
233 int version = int.Parse(words[3]);
234 if (version != 2)
235 return output;
236 break;
237 case 1:
238 words = input[idx].Split(' ');
239 if (words[0] == "LLEmbeddedItems")
240 break;
241 if (words[0] == "Text")
242 {
243 int len = int.Parse(words[2]);
244 idx++;
245
246 int count = -1;
247
248 while (count < len)
249 {
250 // int l = input[idx].Length;
251 string ln = input[idx];
252
253 int need = len-count-1;
254 if (ln.Length > need)
255 ln = ln.Substring(0, need);
256
257 output.Add(ln);
258 count += ln.Length + 1;
259 idx++;
260 }
261
262 return output;
263 }
264 break;
265 case 2:
266 words = input[idx].Split(' '); // count
267 if (words[0] == "count")
268 {
269 int c = int.Parse(words[1]);
270 if (c > 0)
271 return output;
272 break;
273 }
274 break;
275 }
276 idx++;
277 }
278
279 return output;
280 }
184 } 281 }
185} 282} \ No newline at end of file