You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.179
Former-commit-id: a536d4f20e27294d8bbc2184d75f3a22364f7ba1
This commit is contained in:
parent
966bba02bb
commit
fad71374d0
92
external/api-doc-tools/monodoc/Mono.Utilities/LRUCache.cs
vendored
Normal file
92
external/api-doc-tools/monodoc/Mono.Utilities/LRUCache.cs
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mono.Utilities
|
||||
{
|
||||
public class LRUCache<TKey, TValue>
|
||||
{
|
||||
[ThreadStatic]
|
||||
static LRUCache<TKey, TValue> deflt;
|
||||
|
||||
public static LRUCache<TKey, TValue> Default {
|
||||
get {
|
||||
return deflt != null ? deflt : (deflt = new LRUCache<TKey, TValue> (5));
|
||||
}
|
||||
}
|
||||
|
||||
int capacity;
|
||||
LinkedList<ListValueEntry<TKey, TValue>> list;
|
||||
Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>> lookup;
|
||||
LinkedListNode<ListValueEntry<TKey, TValue>> openNode;
|
||||
|
||||
public LRUCache (int capacity)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
this.list = new LinkedList<ListValueEntry<TKey, TValue>>();
|
||||
this.lookup = new Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>> (capacity + 1);
|
||||
this.openNode = new LinkedListNode<ListValueEntry<TKey, TValue>>(new ListValueEntry<TKey, TValue> (default(TKey), default(TValue)));
|
||||
}
|
||||
|
||||
public void Put (TKey key, TValue value)
|
||||
{
|
||||
if (Get(key) == null) {
|
||||
this.openNode.Value.ItemKey = key;
|
||||
this.openNode.Value.ItemValue = value;
|
||||
this.list.AddFirst (this.openNode);
|
||||
this.lookup.Add (key, this.openNode);
|
||||
|
||||
if (this.list.Count > this.capacity) {
|
||||
// last node is to be removed and saved for the next addition to the cache
|
||||
this.openNode = this.list.Last;
|
||||
|
||||
// remove from list & dictionary
|
||||
this.list.RemoveLast();
|
||||
this.lookup.Remove(this.openNode.Value.ItemKey);
|
||||
} else {
|
||||
// still filling the cache, create a new open node for the next time
|
||||
this.openNode = new LinkedListNode<ListValueEntry<TKey, TValue>>(new ListValueEntry<TKey, TValue>(default(TKey), default(TValue)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TValue Get (TKey key)
|
||||
{
|
||||
LinkedListNode<ListValueEntry<TKey, TValue>> node = null;
|
||||
if (!this.lookup.TryGetValue (key, out node))
|
||||
return default (TValue);
|
||||
this.list.Remove (node);
|
||||
this.list.AddFirst (node);
|
||||
return node.Value.ItemValue;
|
||||
}
|
||||
|
||||
class ListValueEntry<K, V> where K : TKey
|
||||
where V : TValue
|
||||
{
|
||||
internal V ItemValue;
|
||||
internal K ItemKey;
|
||||
|
||||
internal ListValueEntry(K key, V value)
|
||||
{
|
||||
this.ItemKey = key;
|
||||
this.ItemValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
92
external/api-doc-tools/monodoc/Mono.Utilities/MemoryLRU.cs
vendored
Normal file
92
external/api-doc-tools/monodoc/Mono.Utilities/MemoryLRU.cs
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mono.Utilities
|
||||
{
|
||||
public class LRUCache<TKey, TValue>
|
||||
{
|
||||
[ThreadStatic]
|
||||
static LRUCache<TKey, TValue> deflt;
|
||||
|
||||
public static LRUCache<TKey, TValue> Default {
|
||||
get {
|
||||
return deflt != null ? deflt : (deflt = new LRUCache<TKey, TValue> (5));
|
||||
}
|
||||
}
|
||||
|
||||
int capacity;
|
||||
LinkedList<ListValueEntry<TKey, TValue>> list;
|
||||
Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>> lookup;
|
||||
LinkedListNode<ListValueEntry<TKey, TValue>> openNode;
|
||||
|
||||
public LRUCache (int capacity)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
this.list = new LinkedList<ListValueEntry<TKey, TValue>>();
|
||||
this.lookup = new Dictionary<TKey, LinkedListNode<ListValueEntry<TKey, TValue>>> (capacity + 1);
|
||||
this.openNode = new LinkedListNode<ListValueEntry<TKey, TValue>>(new ListValueEntry<TKey, TValue> (default(TKey), default(TValue)));
|
||||
}
|
||||
|
||||
public void Put (TKey key, TValue value)
|
||||
{
|
||||
if (Get(key) == null) {
|
||||
this.openNode.Value.Itemkey = key;
|
||||
this.openNode.Value.Itemvalue = value;
|
||||
this.list.AddFirst (this.openNode);
|
||||
this.lookup.Add (key, this.openNode);
|
||||
|
||||
if (this.list.Count > this.capacity) {
|
||||
// last node is to be removed and saved for the next addition to the cache
|
||||
this.openNode = this.list.Last;
|
||||
|
||||
// remove from list & dictionary
|
||||
this.list.RemoveLast();
|
||||
this.lookup.Remove(this.openNode.Value.Itemkey);
|
||||
} else {
|
||||
// still filling the cache, create a new open node for the next time
|
||||
this.openNode = new LinkedListNode<ListValueEntry<Tkey, Tvalue>>(new ListValueEntry<Tkey, Tvalue>(default(Tkey), default(Tvalue)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TValue Get (TKey key)
|
||||
{
|
||||
LinkedListNode<ListValueEntry<TKey, TValue>> node = null;
|
||||
if (!this.lookup.TryGetValue (key, out node))
|
||||
return default (TValue);
|
||||
this.list.Remove (node);
|
||||
this.list.AddFirst (node);
|
||||
return node.Value.ItemValue;
|
||||
}
|
||||
|
||||
class ListValueEntry<K, V> where K : TKey
|
||||
where V : TValue
|
||||
{
|
||||
internal V ItemValue;
|
||||
internal K ItemKey;
|
||||
|
||||
internal ListValueEntry(K key, V value)
|
||||
{
|
||||
this.ItemKey = key;
|
||||
this.ItemValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
171
external/api-doc-tools/monodoc/Mono.Utilities/colorizer.cs
vendored
Normal file
171
external/api-doc-tools/monodoc/Mono.Utilities/colorizer.cs
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections;
|
||||
|
||||
namespace Mono.Utilities {
|
||||
public class Colorizer {
|
||||
//
|
||||
// Syntax coloring
|
||||
//
|
||||
|
||||
static string keywords_cs =
|
||||
"(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|"
|
||||
+
|
||||
"\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|"
|
||||
+
|
||||
"\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|"
|
||||
+
|
||||
"\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|"
|
||||
+
|
||||
"\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|"
|
||||
+
|
||||
"\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|"
|
||||
+
|
||||
"\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|"
|
||||
+
|
||||
"\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|"
|
||||
+ "\\bnamespace\\b|\\bstring\\b)";
|
||||
|
||||
#if false
|
||||
// currently not in use
|
||||
static string keywords_vb =
|
||||
"(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|"
|
||||
+
|
||||
"\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|"
|
||||
+
|
||||
"\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|"
|
||||
+
|
||||
"\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|"
|
||||
+
|
||||
"\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|"
|
||||
+
|
||||
"\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|"
|
||||
+
|
||||
"\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|"
|
||||
+
|
||||
"\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|"
|
||||
+
|
||||
"\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|"
|
||||
+
|
||||
"\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|"
|
||||
+
|
||||
"\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|"
|
||||
+
|
||||
"\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|"
|
||||
+
|
||||
"\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|"
|
||||
+
|
||||
"\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|"
|
||||
+
|
||||
"\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|"
|
||||
+
|
||||
"\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|"
|
||||
+
|
||||
"\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
|
||||
#endif
|
||||
|
||||
public static string Colorize(string text, string lang)
|
||||
{
|
||||
lang = lang.Trim().ToLower();
|
||||
switch (lang) {
|
||||
case "xml":
|
||||
return ColorizeXml(text);
|
||||
case "cs": case "c#": case "csharp":
|
||||
return ColorizeCs(text);
|
||||
case "vb":
|
||||
return ColorizeVb(text);
|
||||
}
|
||||
return Escape (text);
|
||||
}
|
||||
|
||||
static string ColorizeXml(string text)
|
||||
{
|
||||
// Order is highly important.
|
||||
|
||||
// s/ / /g must be first, as later substitutions add required spaces
|
||||
text = text.Replace(" ", " ");
|
||||
|
||||
// Find & mark XML elements
|
||||
Regex re = new Regex("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
|
||||
text = re.Replace(text, "{blue:<$1}{maroon:$2}{blue:$3>}");
|
||||
|
||||
// Colorize attribute strings; must be done before colorizing marked XML
|
||||
// elements so that we don't clobber the colorized XML tags.
|
||||
re = new Regex ("([\"'])(.*?)\\1");
|
||||
text = re.Replace (text,
|
||||
"$1<font color=\"purple\">$2</font>$1");
|
||||
|
||||
// Colorize marked XML elements
|
||||
re = new Regex("\\{(\\w*):([\\s\\S]*?)\\}");
|
||||
//text = re.Replace(text, "<span style='color:$1'>$2</span>");
|
||||
text = re.Replace(text, "<font color=\"$1\">$2</font>");
|
||||
|
||||
// Standard Structure
|
||||
text = text.Replace("\t", " ");
|
||||
re = new Regex("\r\n|\r|\n");
|
||||
text = re.Replace(text, "<br/>");
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static string ColorizeCs(string text)
|
||||
{
|
||||
text = text.Replace(" ", " ");
|
||||
|
||||
text = text.Replace("<", "<");
|
||||
text = text.Replace(">", ">");
|
||||
|
||||
Regex re = new Regex("\"((((?!\").)|\\\")*?)\"");
|
||||
|
||||
text =
|
||||
re.Replace(text,
|
||||
"<font color=\"purple\">\"$1\"</font>");
|
||||
//"<span style='color:purple'>\"$1\"</span>");
|
||||
|
||||
re = new
|
||||
Regex
|
||||
("//(((.(?!\"</font>))|\"(((?!\").)*)\"</font>)*)(\r|\n|\r\n)");
|
||||
//("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
|
||||
text =
|
||||
re.Replace(text,
|
||||
"<font color=\"green\">//$1</font><br/>");
|
||||
// "<span style='color:green'>//$1</span><br/>");
|
||||
|
||||
re = new Regex(keywords_cs);
|
||||
text = re.Replace(text, "<font color=\"blue\">$1</font>");
|
||||
//text = re.Replace(text, "<span style='color:blue'>$1</span>");
|
||||
|
||||
text = text.Replace("\t", " ");
|
||||
text = text.Replace("\n", "<br/>");
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static string ColorizeVb(string text) {
|
||||
text = text.Replace(" ", " ");
|
||||
|
||||
/* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
|
||||
text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
|
||||
|
||||
re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
|
||||
text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
|
||||
|
||||
re = new Regex (keywords_vb);
|
||||
text = re.Replace (text,"<span style='color:blue'>$1</span>");
|
||||
*/
|
||||
text = text.Replace("\t", " ");
|
||||
text = text.Replace("\n", "<br/>");
|
||||
return text;
|
||||
}
|
||||
|
||||
static string Escape(string text)
|
||||
{
|
||||
text = text.Replace("&", "&");
|
||||
text = text.Replace(" ", " ");
|
||||
text = text.Replace("<", "<");
|
||||
text = text.Replace(">", ">");
|
||||
text = text.Replace("\n", "<br/>");
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user