本文整理汇总了C#中NHibernate.Util.StringTokenizer类的典型用法代码示例。如果您正苦于以下问题:C# StringTokenizer类的具体用法?C# StringTokenizer怎么用?C# StringTokenizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringTokenizer类属于NHibernate.Util命名空间,在下文中一共展示了StringTokenizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NotSoSimpleWithDelimiters
public void NotSoSimpleWithDelimiters()
{
string s = "The lazy... I don't know ";
StringTokenizer st = new StringTokenizer(s, " .", true);
IEnumerator enumerator = st.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual("The", (string) enumerator.Current, "Can't get first token");
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get first space");
enumerator.MoveNext();
Assert.AreEqual("lazy", (string) enumerator.Current, "Can't get second token");
enumerator.MoveNext();
Assert.AreEqual(".", (string) enumerator.Current, "Can't get first dot");
enumerator.MoveNext();
Assert.AreEqual(".", (string) enumerator.Current, "Can't get second dot");
enumerator.MoveNext();
Assert.AreEqual(".", (string) enumerator.Current, "Can't get third dot");
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get second space");
enumerator.MoveNext();
Assert.AreEqual("I", (string) enumerator.Current, "Can't get third token");
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get third space");
enumerator.MoveNext();
Assert.AreEqual("don't", (string) enumerator.Current, "Can't get fourth token");
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get fourth space");
enumerator.MoveNext();
Assert.AreEqual("know", (string) enumerator.Current, "Can't get fifth token");
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get last space");
Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
}
示例2: BindIndex
protected static void BindIndex(XmlAttribute indexAttribute, Table table, Column column)
{
if (indexAttribute != null && table != null)
{
StringTokenizer tokens = new StringTokenizer(indexAttribute.Value, ", ");
foreach (string token in tokens)
table.GetOrCreateIndex(token).AddColumn(column);
}
}
示例3: Parse
public static void Parse(IParser p, string text, string seperators, QueryTranslator q)
{
StringTokenizer tokens = new StringTokenizer(text, seperators, true);
p.Start(q);
foreach (string token in tokens)
{
p.Token(token, q);
}
p.End(q);
}
示例4: SimpleStringWithoutDelimiters
public void SimpleStringWithoutDelimiters()
{
string s = "Hello world!";
StringTokenizer st = new StringTokenizer(s);
IEnumerator enumerator = st.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual("Hello", (string) enumerator.Current, "Can't get first token");
enumerator.MoveNext();
Assert.AreEqual("world!", (string) enumerator.Current, "Can't get second token");
Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
}
示例5: Format
private static string Format(string sql)
{
if (sql.IndexOf("\"") > 0 || sql.IndexOf("'") > 0)
{
return sql;
}
string formatted;
if (sql.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith("create table"))
{
StringBuilder result = new StringBuilder(60);
StringTokenizer tokens = new StringTokenizer(sql, "(,)", true);
int depth = 0;
foreach (string tok in tokens)
{
if (StringHelper.ClosedParen.Equals(tok))
{
depth--;
if (depth == 0)
{
result.AppendLine();
}
}
result.Append(tok);
if (StringHelper.Comma.Equals(tok) && depth == 1)
{
result.AppendLine().Append(' ');
}
if (StringHelper.OpenParen.Equals(tok))
{
depth++;
if (depth == 1)
{
result.AppendLine().Append(' ');
}
}
}
formatted = result.ToString();
}
else
{
formatted = sql;
}
return formatted;
}
示例6: ToDictionary
/// <summary>
///
/// </summary>
/// <param name="property"></param>
/// <param name="delim"></param>
/// <param name="properties"></param>
/// <returns></returns>
public static IDictionary ToDictionary( string property, string delim, IDictionary properties )
{
IDictionary map = new Hashtable();
string propValue = ( string ) properties[ property ];
if( propValue != null )
{
StringTokenizer tokens = new StringTokenizer( propValue, delim, false );
IEnumerator en = tokens.GetEnumerator();
while( en.MoveNext() )
{
string key = ( string ) en.Current;
string value = en.MoveNext() ? ( string ) en.Current : String.Empty;
map[ key ] = value;
}
}
return map;
}
示例7: ToDictionary
public static IDictionary<string, string> ToDictionary(string property, string delim, IDictionary<string, string> properties)
{
IDictionary<string, string> map = new Dictionary<string, string>();
if (properties.ContainsKey(property))
{
string propValue = properties[property];
StringTokenizer tokens = new StringTokenizer(propValue, delim, false);
IEnumerator<string> en = tokens.GetEnumerator();
while (en.MoveNext())
{
string key = en.Current;
string value = en.MoveNext() ? en.Current : String.Empty;
map[key] = value;
}
}
return map;
}
示例8: Split
/// <summary>
/// Splits the String using the StringTokenizer.
/// </summary>
/// <param name="separators">separators for the tokens of the list</param>
/// <param name="list">the string that will be broken into tokens</param>
/// <param name="include">true to include the separators in the tokens.</param>
/// <returns></returns>
/// <remarks>
/// This is more powerful than Split because you have the option of including or
/// not including the separators in the tokens.
/// </remarks>
public static string[] Split(string separators, string list, bool include)
{
var tokens = new StringTokenizer(list, separators, include);
return tokens.ToArray();
}
示例9: Format
/// <summary>
/// Format an SQL statement using simple rules
/// </summary>
/// <param name="sql">The string containing the sql to format.</param>
/// <returns>A string that contains formatted sql.</returns>
/// <remarks>
/// The simple rules to used when formatting are:
/// <list type="number">
/// <item>
/// <description>Insert a newline after each comma</description>
/// </item>
/// <item>
/// <description>Indent three spaces after each inserted newline</description>
/// </item>
/// <item>
/// <description>
/// If the statement contains single/double quotes return unchanged because
/// it is too complex and could be broken by simple formatting.
/// </description>
/// </item>
/// </list>
/// </remarks>
private static string Format(string sql)
{
if (sql.IndexOf("\"") > 0 || sql.IndexOf("'") > 0)
{
return sql;
}
string formatted;
if (StringHelper.StartsWithCaseInsensitive(sql, "create table"))
{
StringBuilder result = new StringBuilder(60);
StringTokenizer tokens = new StringTokenizer(sql, "(,)", true);
int depth = 0;
foreach (string tok in tokens)
{
if (StringHelper.ClosedParen.Equals(tok))
{
depth--;
if (depth == 0)
{
result.Append("\n");
}
}
result.Append(tok);
if (StringHelper.Comma.Equals(tok) && depth == 1)
{
result.Append("\n ");
}
if (StringHelper.OpenParen.Equals(tok))
{
depth++;
if (depth == 1)
{
result.Append("\n ");
}
}
}
formatted = result.ToString();
}
else
{
formatted = sql;
}
return formatted;
}
示例10: DoPathExpression
private void DoPathExpression(string token, QueryTranslator q)
{
Preprocess(token, q);
StringTokenizer tokens = new StringTokenizer(token, ".", true);
pathExpressionParser.Start(q);
foreach (string tok in tokens)
{
pathExpressionParser.Token(tok, q);
}
pathExpressionParser.End(q);
if (pathExpressionParser.IsCollectionValued)
{
OpenExpression(q, string.Empty);
AppendToken(q, pathExpressionParser.GetCollectionSubquery(q.EnabledFilters));
CloseExpression(q, string.Empty);
// this is ugly here, but needed because its a subquery
q.AddQuerySpaces(q.GetCollectionPersister(pathExpressionParser.CollectionRole).CollectionSpaces);
}
else
{
if (pathExpressionParser.IsExpectingCollectionIndex)
{
expectingIndex++;
}
else
{
AddJoin(pathExpressionParser.WhereJoin, q);
AppendToken(q, pathExpressionParser.WhereColumn);
}
}
}
示例11: ProcessFilters
public void ProcessFilters(SqlString sql, ISessionImplementor session)
{
filteredParameterValues = new List<object>();
filteredParameterTypes = new List<IType>();
filteredParameterLocations = new List<int>();
if (session.EnabledFilters.Count == 0 || sql.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
{
processedSQL = sql.Copy();
return;
}
Dialect.Dialect dialect = session.Factory.Dialect;
string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;
var result = new SqlStringBuilder();
int originalParameterIndex = 0; // keep track of the positional parameter
int newParameterIndex = 0;
_adjustedParameterLocations = new Dictionary<int, int>();
foreach (var part in sql.Parts)
{
if (part is Parameter)
{
result.AddParameter();
// (?) can be a position parameter or a named parameter (already substituted by (?),
// but only the positional parameters are available at this point. Adding them in the
// order of appearance is best that can be done at this point of time, but if they
// are mixed with named parameters, the order is still wrong, because values and
// types for the named parameters are added later to the end of the list.
// see test fixture NH-1098
_adjustedParameterLocations[originalParameterIndex] = newParameterIndex;
originalParameterIndex++;
newParameterIndex++;
continue;
}
var tokenizer = new StringTokenizer((string) part, symbols, true);
foreach (var token in tokenizer)
{
if (token.StartsWith(ParserHelper.HqlVariablePrefix))
{
string filterParameterName = token.Substring(1);
object value = session.GetFilterParameterValue(filterParameterName);
IType type = session.GetFilterParameterType(filterParameterName);
// If the value is not a value of the type but a collection of values...
if (value != null && !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882
typeof (ICollection).IsAssignableFrom(value.GetType()))
{
var coll = (ICollection) value;
int i = 0;
foreach (var elementValue in coll)
{
i++;
int span = type.GetColumnSpan(session.Factory);
if (span > 0)
{
result.AddParameter();
filteredParameterTypes.Add(type);
filteredParameterValues.Add(elementValue);
filteredParameterLocations.Add(newParameterIndex);
newParameterIndex++;
if (i < coll.Count)
{
result.Add(", ");
}
}
}
}
else
{
int span = type.GetColumnSpan(session.Factory);
if (span > 0)
{
result.AddParameter();
filteredParameterTypes.Add(type);
filteredParameterValues.Add(value);
filteredParameterLocations.Add(newParameterIndex);
newParameterIndex++;
}
}
}
else
{
result.Add(token);
}
}
}
processedSQL = result.ToSqlString();
}
示例12: ExpandDynamicFilterParameters
protected SqlString ExpandDynamicFilterParameters(SqlString sqlString, ICollection<IParameterSpecification> parameterSpecs, ISessionImplementor session)
{
var enabledFilters = session.EnabledFilters;
if (enabledFilters.Count == 0 || sqlString.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0)
{
return sqlString;
}
Dialect.Dialect dialect = session.Factory.Dialect;
string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote;
var originSql = sqlString.Compact();
var result = new SqlStringBuilder();
foreach (var sqlPart in originSql.Parts)
{
var parameter = sqlPart as Parameter;
if (parameter != null)
{
result.Add(parameter);
continue;
}
var sqlFragment = sqlPart.ToString();
var tokens = new StringTokenizer(sqlFragment, symbols, true);
foreach (string token in tokens)
{
if (token.StartsWith(ParserHelper.HqlVariablePrefix))
{
string filterParameterName = token.Substring(1);
string[] parts = StringHelper.ParseFilterParameterName(filterParameterName);
string filterName = parts[0];
string parameterName = parts[1];
var filter = (FilterImpl)enabledFilters[filterName];
object value = filter.GetParameter(parameterName);
IType type = filter.FilterDefinition.GetParameterType(parameterName);
int parameterColumnSpan = type.GetColumnSpan(session.Factory);
var collectionValue = value as ICollection;
int? collectionSpan = null;
// Add query chunk
string typeBindFragment = string.Join(", ", Enumerable.Repeat("?", parameterColumnSpan).ToArray());
string bindFragment;
if (collectionValue != null && !type.ReturnedClass.IsArray)
{
collectionSpan = collectionValue.Count;
bindFragment = string.Join(", ", Enumerable.Repeat(typeBindFragment, collectionValue.Count).ToArray());
}
else
{
bindFragment = typeBindFragment;
}
// dynamic-filter parameter tracking
var filterParameterFragment = SqlString.Parse(bindFragment);
var dynamicFilterParameterSpecification = new DynamicFilterParameterSpecification(filterName, parameterName, type, collectionSpan);
var parameters = filterParameterFragment.GetParameters().ToArray();
var sqlParameterPos = 0;
var paramTrackers = dynamicFilterParameterSpecification.GetIdsForBackTrack(session.Factory);
foreach (var paramTracker in paramTrackers)
{
parameters[sqlParameterPos++].BackTrack = paramTracker;
}
parameterSpecs.Add(dynamicFilterParameterSpecification);
result.Add(filterParameterFragment);
}
else
{
result.Add(token);
}
}
}
return result.ToSqlString().Compact();
}
示例13: AddColumnsFromList
private void AddColumnsFromList(HbmId idSchema, SimpleValue id)
{
int count = 0;
foreach (HbmColumn columnSchema in idSchema.column ?? new HbmColumn[0])
{
Column column = CreateColumn(columnSchema, id, count++);
column.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);
if (id.Table != null)
id.Table.AddColumn(column);
//table=null -> an association, fill it in later
id.AddColumn(column);
if (columnSchema.index != null && id.Table != null)
{
StringTokenizer tokens = new StringTokenizer(columnSchema.index, ", ");
foreach (string token in tokens)
id.Table.GetOrCreateIndex(token).AddColumn(column);
}
if (columnSchema.uniquekey != null && id.Table != null)
{
StringTokenizer tokens = new StringTokenizer(columnSchema.uniquekey, ", ");
foreach (string token in tokens)
id.Table.GetOrCreateUniqueKey(token).AddColumn(column);
}
}
}
示例14: Replace
private string Replace(string message, object entity)
{
var tokens = new StringTokenizer(message, "#${}", true);
var buf = new StringBuilder(100);
var escaped = false;
var el = false;
var isMember = false;
IEnumerator ie = tokens.GetEnumerator();
while (ie.MoveNext())
{
string token = (string) ie.Current;
if (!escaped && "#".Equals(token))
{
el = true;
}
if(!el && ("$".Equals(token)))
{
isMember = true;
}
else if("}".Equals(token) && isMember)
{
isMember = false;
}
if (!el && "{".Equals(token))
{
escaped = true;
}
else if (escaped && "}".Equals(token))
{
escaped = false;
}
else if (!escaped)
{
if ("{".Equals(token))
{
el = false;
}
if(!"$".Equals(token)) buf.Append(token);
}
else if(!isMember)
{
object variable;
if (attributeParameters.TryGetValue(token.ToLowerInvariant(), out variable))
{
buf.Append(variable);
}
else
{
string _string = null;
try
{
_string = messageBundle != null ? messageBundle.GetString(token, culture) : null;
}
catch (MissingManifestResourceException)
{
//give a second chance with the default resource bundle
}
if (_string == null)
{
_string = defaultMessageBundle.GetString(token, culture);
// in this case we don't catch the MissingManifestResourceException because
// we are sure that we DefaultValidatorMessages.resx is an embedded resource
}
if (_string == null)
{
buf.Append('{').Append(token).Append('}');
}
else
{
buf.Append(Replace(_string,entity));
}
}
}
else
{
ReplaceValue(buf, entity, token);
}
}
return buf.ToString();
}
示例15: GetPathInfo
private ICriteriaInfoProvider GetPathInfo(string path)
{
StringTokenizer tokens = new StringTokenizer(path, ".", false);
string componentPath = string.Empty;
// start with the 'rootProvider'
ICriteriaInfoProvider provider;
if (nameCriteriaInfoMap.TryGetValue(rootEntityName, out provider) == false)
throw new ArgumentException("Could not find ICriteriaInfoProvider for: " + path);
foreach (string token in tokens)
{
componentPath += token;
logger.DebugFormat("searching for {0}", componentPath);
IType type = provider.GetType(componentPath);
if (type.IsAssociationType)
{
// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
IAssociationType atype = (IAssociationType)type;
CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null;
IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null;
// is the association a collection of components or value-types? (i.e a colloction of valued types?)
if (ctype != null && elementType.IsComponentType)
{
provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role));
}
else if (ctype != null && !elementType.IsEntityType)
{
provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role);
}
else
{
provider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister(
atype.GetAssociatedEntityName(
sessionFactory)
));
}
componentPath = string.Empty;
}
else if (type.IsComponentType)
{
componentPath += '.';
}
else
{
throw new QueryException("not an association: " + componentPath);
}
}
logger.DebugFormat("returning entity name={0} for path={1} class={2}",
provider.Name, path, provider.GetType().Name);
return provider;
}