public void StringAtomGetHashCodeTest() { const string value = "test"; var atom = new StringAtom(value); atom.GetHashCode().Should().Be(-354185609); }
protected int LoadFileCache(Dictionary <StringAtom, FileUri> cache, FileUri uri, StringAtom path) { int count = 0; FileLoc loc; loc.uri = uri; loc.modPath = this.ModPath; string txt = util.File.LoadTxt(loc, App.Language, path.Str); if (txt == null) { return(0); } StringReader sr = new StringReader(txt); while (true) { string line = sr.ReadLine(); if (line == null) { break; } string regline = line.Trim(); if (!string.IsNullOrEmpty(regline)) { StringAtom realpath = StringAtom.FromStr(regline); cache[realpath] = uri; ++count; } } sr.Close(); return(count); }
public void StringAtomEqualsNullParameterTest() { const string value = "test"; var atom = new StringAtom(value); atom.Equals(null).Should().BeFalse(); }
public void StringAtomEqualsTest(string firstValue, string secondValue, bool expected) { var atom = new StringAtom(firstValue); var compareAtom = new StringAtom(secondValue); atom.Equals(compareAtom).Should().Be(expected); }
public void StringAtomConstructorTest() { const string value = "Test"; var atom = new StringAtom(value); atom.Should().NotBeNull(); atom.Type.Should().Be(AtomType.String); atom.Value.Should().Be(value); }
public void StringAtomDumpNullParameterTest() { const string value = "test"; var atom = new StringAtom(value); const string prefix = "Test"; Action act = () => atom.Dump(null, prefix); act.Should().Throw <ArgumentNullException>(); }
public void StringAtomDumpTest() { var callback = false; var logger = A.Fake <ILogWrapper>(); A.CallTo(() => logger.InfoFormat(A <string> .Ignored, A <object> .Ignored, A <object> .Ignored)) .Invokes(() => callback = true); const string value = "Test"; var atom = new StringAtom(value); const string prefix = "Test"; atom.Dump(logger, prefix); callback.Should().BeTrue(); }
/// <summary> /// Gets the file location. /// </summary> /// <returns>The file location.</returns> /// <param name="lang">If set to <c>true</c> lang.</param> /// <param name="path">Path.</param> public FileUri GetFileUri(bool lang, StringAtom path) { FileUri loc; if (lang) { if (langFileCache.TryGetValue(path, out loc)) { return(loc); } } else { if (fileCache.TryGetValue(path, out loc)) { return(loc); } } return(FileUri.UNKNOWN); }
public int LoadFileCache() { int count = 0; if (!isFileCacheLoaded) { if (langFileCache == null) { langFileCache = new Dictionary <StringAtom, FileUri>(); } if (fileCache == null) { fileCache = new Dictionary <StringAtom, FileUri>(); } StringAtom fileCacheName = StringAtom.FromStr("filecache.txt"); StringAtom langPath = null; if (!string.IsNullOrEmpty(App.Language)) { langPath = StringAtom.FromStr(App.Language + "/filecache.txt"); } //resource no lang count += LoadFileCache(fileCache, FileUri.RES_DIR, fileCacheName); if (langPath != null) { //resource lang count += LoadFileCache(langFileCache, FileUri.RES_LANG_DIR, langPath); } //steam no lang count += LoadFileCache(fileCache, FileUri.STREAM_DIR, fileCacheName); if (langPath != null) { //steam lang count += LoadFileCache(langFileCache, FileUri.STREAM_LANG_DIR, langPath); } //patch no lang count += LoadFileCache(fileCache, FileUri.PATCH_DIR, fileCacheName); if (langPath != null) { //patch lang count += LoadFileCache(langFileCache, FileUri.PATCH_LANG_DIR, langPath); } Mod nextMod = parent; while (nextMod != null) { nextMod.LoadFileCache(); nextMod = nextMod.parent; } isFileCacheLoaded = true; } return(count); }
private void ReadPseudoListContent(PseudoList list, IList <IToken> tokens, ref int index, int depth) { while (true) { if (index == tokens.Count) { if (depth > 0) { throw new TinyLispException("Unclosed form."); } else { return; } } var token = tokens[index]; if (token is LispPunctuationToken punctuationToken) { switch (punctuationToken.Value) { case Punctuation.RightParenthesis: if (depth == 0) { throw new TinyLispException("Unexpected ')'."); } else { index++; return; } case Punctuation.LeftParenthesis: index++; var innerList = new PseudoList(); this.ReadPseudoListContent(innerList, tokens, ref index, depth + 1); list.AddElement(innerList); break; default: throw new ArgumentOutOfRangeException(); } } else if (token is KeywordToken keywordToken) { var element = Symbol.Create(keywordToken.Keyword); list.AddElement(element); index++; } else if (token is LispSymbolToken symbolToken) { var element = Symbol.Create(symbolToken.SymbolName); list.AddElement(element); index++; } else if (token is TextToken textToken && textToken.Class is StringTextClass) { var element = new StringAtom(textToken.Text); list.AddElement(element); index++; }
public ArrayAtom GetTextOperator() { Debug.Assert(_text != null); // get data and widths byte[] section = new byte[_text.StreamLength]; Array.Copy(_data, _text.StreamOffset, section, 0, _text.StreamLength); IDictionary <char, int> widths = _text.Font.Widths; // convert to atoms ArrayAtom textOp = ArrayAtom.FromContentStream(section); string srcOp = ((OpAtom)textOp[1]).Text; int numParams = srcOp == "\"" ? 4 : 2; Debug.Assert(textOp.Count == numParams); ArrayAtom srcParams = textOp[numParams == 4 ? 2 : 0] as ArrayAtom; if (srcParams == null) { Debug.Assert(srcOp != "TJ"); srcParams = new ArrayAtom(); srcParams.Add(textOp[0]); } ArrayAtom dstParams = new ArrayAtom(); // copy items int textSpanIndex = 0; for (int i = 0; i < srcParams.Count; i++) { Atom item = srcParams[i]; if (item is StringAtom) { StringAtom str = (StringAtom)item; Tuple <string, bool[]> redaction = null; _redactions.TryGetValue(textSpanIndex++, out redaction); if (redaction == null) { dstParams.Add(item.Clone()); } else { string encoded = str.Text; string whole = redaction.Item1; bool[] redacted = redaction.Item2; Debug.Assert((encoded.Length == whole.Length) || (encoded.Length == whole.Length * 2)); int bytesPerChar = encoded.Length / whole.Length; int p1 = 0; while (p1 < redacted.Length) { bool hidden = redacted[p1]; int width1000ths = 0; int p2; for (p2 = p1; p2 < redacted.Length; p2++) { if (hidden != redacted[p2]) { break; } if (hidden) { width1000ths += widths[whole[p2]]; } } if (hidden) { dstParams.Add(new NumAtom(-width1000ths)); } else { string sub1 = encoded.Substring(p1 * bytesPerChar, (p2 - p1) * bytesPerChar); if (sub1.Length > 0) { dstParams.Add(new StringAtom(sub1)); } } p1 = p2; } } } else if (item is NumAtom) { NumAtom num = (NumAtom)item; dstParams.Add(item.Clone()); } else { Debug.Assert(false); } } // make new operators ArrayAtom newTextOp = new ArrayAtom(); if (srcOp == "\'") { newTextOp.Add(new OpAtom("T*")); } else if (srcOp == "\"") { newTextOp.Add(textOp[0].Clone()); newTextOp.Add(new OpAtom("Tw")); newTextOp.Add(textOp[1].Clone()); newTextOp.Add(new OpAtom("Tc")); newTextOp.Add(new OpAtom("T*")); } newTextOp.Add(dstParams); newTextOp.Add(new OpAtom("TJ")); return(newTextOp); }