本文整理汇总了C#中NHibernate.Util.StringTokenizer.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# StringTokenizer.GetEnumerator方法的具体用法?C# StringTokenizer.GetEnumerator怎么用?C# StringTokenizer.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Util.StringTokenizer
的用法示例。
在下文中一共展示了StringTokenizer.GetEnumerator方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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");
}
示例3: 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;
}
示例4: 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;
}
示例5: 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();
}
示例6: RenderWhereStringTemplate
public static string RenderWhereStringTemplate(string sqlWhereString, string placeholder, Dialect.Dialect dialect,
SQLFunctionRegistry functionRegistry)
{
//TODO: make this a bit nicer
string symbols = new StringBuilder()
.Append("=><!+-*/()',|&`")
.Append(ParserHelper.Whitespace)
.Append(dialect.OpenQuote)
.Append(dialect.CloseQuote)
.ToString();
StringTokenizer tokens = new StringTokenizer(sqlWhereString, symbols, true);
StringBuilder result = new StringBuilder();
bool quoted = false;
bool quotedIdentifier = false;
bool beforeTable = false;
bool inFromClause = false;
bool afterFromTable = false;
IEnumerator tokensEnum = tokens.GetEnumerator();
bool hasMore = tokensEnum.MoveNext();
string nextToken = hasMore ? (string) tokensEnum.Current : null;
while (hasMore)
{
string token = nextToken;
string lcToken = token.ToLower(CultureInfo.InvariantCulture);
hasMore = tokensEnum.MoveNext();
nextToken = hasMore ? (string) tokensEnum.Current : null;
bool isQuoteCharacter = false;
if (!quotedIdentifier && "'".Equals(token))
{
quoted = !quoted;
isQuoteCharacter = true;
}
if (!quoted)
{
bool isOpenQuote;
if ("`".Equals(token))
{
isOpenQuote = !quotedIdentifier;
token = lcToken = isOpenQuote ?
dialect.OpenQuote.ToString() :
dialect.CloseQuote.ToString();
quotedIdentifier = isOpenQuote;
isQuoteCharacter = true;
}
else if (!quotedIdentifier && (dialect.OpenQuote == token[0]))
{
isOpenQuote = true;
quotedIdentifier = true;
isQuoteCharacter = true;
}
else if (quotedIdentifier && (dialect.CloseQuote == token[0]))
{
quotedIdentifier = false;
isQuoteCharacter = true;
isOpenQuote = false;
}
else
{
isOpenQuote = false;
}
if (isOpenQuote)
{
result.Append(placeholder).Append('.');
}
}
bool quotedOrWhitespace = quoted ||
quotedIdentifier ||
isQuoteCharacter ||
char.IsWhiteSpace(token[0]);
if (quotedOrWhitespace)
{
result.Append(token);
}
else if (beforeTable)
{
result.Append(token);
beforeTable = false;
afterFromTable = true;
}
else if (afterFromTable)
{
if (!"as".Equals(lcToken))
afterFromTable = false;
result.Append(token);
}
else if (IsNamedParameter(token))
{
result.Append(token);
}
else if (
IsIdentifier(token, dialect) &&
!IsFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry)
//.........这里部分代码省略.........
示例7: RenderOrderByStringTemplate
public static string RenderOrderByStringTemplate(string sqlOrderByString, Dialect.Dialect dialect,
SQLFunctionRegistry functionRegistry)
{
//TODO: make this a bit nicer
string symbols = new StringBuilder()
.Append("=><!+-*/()',|&`")
.Append(ParserHelper.Whitespace)
.Append(dialect.OpenQuote)
.Append(dialect.CloseQuote)
.ToString();
StringTokenizer tokens = new StringTokenizer(sqlOrderByString, symbols, true);
StringBuilder result = new StringBuilder();
bool quoted = false;
bool quotedIdentifier = false;
IEnumerator<string> tokensEnum = tokens.GetEnumerator();
bool hasMore = tokensEnum.MoveNext();
string nextToken = hasMore ? tokensEnum.Current : null;
while (hasMore)
{
string token = nextToken;
string lcToken = token.ToLowerInvariant();
hasMore = tokensEnum.MoveNext();
nextToken = hasMore ? tokensEnum.Current : null;
bool isQuoteCharacter = false;
if (!quotedIdentifier && "'".Equals(token))
{
quoted = !quoted;
isQuoteCharacter = true;
}
if (!quoted)
{
bool isOpenQuote;
if ("`".Equals(token))
{
isOpenQuote = !quotedIdentifier;
token = lcToken = isOpenQuote ?
dialect.OpenQuote.ToString() :
dialect.CloseQuote.ToString();
quotedIdentifier = isOpenQuote;
isQuoteCharacter = true;
}
else if (!quotedIdentifier && (dialect.OpenQuote == token[0]))
{
isOpenQuote = true;
quotedIdentifier = true;
isQuoteCharacter = true;
}
else if (quotedIdentifier && (dialect.CloseQuote == token[0]))
{
quotedIdentifier = false;
isQuoteCharacter = true;
isOpenQuote = false;
}
else
{
isOpenQuote = false;
}
if (isOpenQuote)
{
result.Append(Placeholder).Append('.');
}
}
bool quotedOrWhitespace = quoted ||
quotedIdentifier ||
isQuoteCharacter ||
char.IsWhiteSpace(token[0]);
if (quotedOrWhitespace)
{
result.Append(token);
}
else if (
IsIdentifier(token, dialect) &&
!IsFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry)
)
{
result.Append(Placeholder)
.Append('.')
.Append(token);
}
else
{
result.Append(token);
}
}
return result.ToString();
}
示例8: OnlyDelimitersWithoutDelimiters
public void OnlyDelimitersWithoutDelimiters()
{
string s = " .,,,";
StringTokenizer st = new StringTokenizer(s, " ,.", false);
IEnumerator enumerator = st.GetEnumerator();
Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
}
示例9: OnlyDelimitersWithDelimiters
public void OnlyDelimitersWithDelimiters()
{
string s = " .,,,";
StringTokenizer st = new StringTokenizer(s, " ,.", true);
IEnumerator enumerator = st.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual(" ", (string) enumerator.Current, "Can't get first delimiter");
enumerator.MoveNext();
Assert.AreEqual(".", (string) enumerator.Current, "Can't get second delimiter");
enumerator.MoveNext();
Assert.AreEqual(",", (string) enumerator.Current, "Can't get third delimiter");
enumerator.MoveNext();
Assert.AreEqual(",", (string) enumerator.Current, "Can't get fourth delimiter");
enumerator.MoveNext();
Assert.AreEqual(",", (string) enumerator.Current, "Can't get fifth delimiter");
Assert.AreEqual(false, enumerator.MoveNext(), "Still thinking there are more tokens");
}
示例10: ResolveArgument
private IActor ResolveArgument(IActor resolvedActor, String expression, int index)
{
String argument = null;
String whiteSpace = " ".Substring(0, index);
String[] parameters = null;
int argumentEndIndex = expression.IndexOf("->", index);
if (argumentEndIndex == -1)
{
argumentEndIndex = expression.Length;
}
int parametersStartIndex = expression.IndexOf("(", index);
int parametersEndIndex = -1;
if ((parametersStartIndex != -1) && (parametersStartIndex < argumentEndIndex))
{
argument = expression.Substring(index, (parametersStartIndex) - (index)).Trim();
parametersEndIndex = expression.IndexOf(")", parametersStartIndex + 1);
if (parametersEndIndex > argumentEndIndex)
{
throw new SystemException("can't resolve assigner expression : couldn't find closing bracket for bracket on index '" + parametersStartIndex + "' in expression '" + expression + "'");
}
// the next exception happens when a parameter contains a right bracket.
String shouldBewhiteSpace = expression.Substring(parametersEndIndex + 1, (argumentEndIndex) - (parametersEndIndex + 1));
if (!"".Equals(shouldBewhiteSpace.Trim()))
{
throw new SystemException("can't resolve assigner expression : only whitespace allowed between closing bracket of the parameterlist of an argument and the end of the argument : closing bracket position '" + parametersEndIndex + "' in expression '" + expression + "'");
}
String parametersText = expression.Substring(parametersStartIndex + 1, (parametersEndIndex) - (parametersStartIndex + 1));
ArrayList parameterList = new ArrayList();
StringTokenizer tokenizer = new StringTokenizer(parametersText, ",");
IEnumerator tokenEnum = tokenizer.GetEnumerator();
while (tokenEnum.MoveNext())
{
parameterList.Add(tokenEnum.Current.ToString().Trim());
}
if (parameterList.Count > 0)
{
parameters = new String[parameterList.Count];
parameters = (String[])parameterList.ToArray(typeof(String));
}
else
{
parameters = new String[0];
}
}
else
{
argument = expression.Substring(index, (argumentEndIndex) - (index)).Trim();
parameters = new String[0];
}
if ("".Equals(argument))
{
throw new SystemException("can't resolve assigner expression : can't resolve empty argument on index '" + index + "' for expression '" + expression + "'");
}
String methodName = "ResolveArgument" + argument.Substring(0, 1).ToUpper() + argument.Substring(1);
try
{
MethodInfo method = this.GetType().GetMethod(methodName, (Type[])RESOLVE_METHOD_ARGUMENT_TYPES);
Object[] args = new Object[] { resolvedActor, parameters };
resolvedActor = (IActor)method.Invoke(this, (Object[])args);
}
catch (Exception t)
{
throw new SystemException("can't resolve assigner expression : couldn't resolve argument '" + argument + "' : " + t.Message, t);
}
if (argumentEndIndex != expression.Length)
{
if (argumentEndIndex < expression.Length)
{
argumentEndIndex = expression.IndexOf("->", argumentEndIndex) + 2;
}
resolvedActor = ResolveArgument(resolvedActor, expression, argumentEndIndex);
}
return resolvedActor;
}
示例11: RenderWhereStringTemplate
/// <summary>
/// Takes the where condition provided in the mapping attribute and iterpolates the alias.
/// </summary>
/// <param name="whereSql">The "where" sql statement from the mapping attribute.</param>
/// <param name="dialect">The <see cref="Dialect.Dialect"/> to help with rendering the Sql.</param>
/// <returns>
/// A well formed "where" sql statement for the <see cref="Dialect.Dialect"/>.
/// </returns>
public static string RenderWhereStringTemplate( string whereSql, Dialect.Dialect dialect )
{
//TODO: make this a bit nicer.
StringTokenizer tokens = new StringTokenizer( whereSql, delimiters, true );
StringBuilder result = new StringBuilder( whereSql.Length + 10 );
bool quoted = false;
bool afterFrom = false;
bool afterFromTable = false;
IEnumerator tokensEnum = tokens.GetEnumerator();
bool hasMore = tokensEnum.MoveNext();
string nextToken = hasMore ? ( string ) tokensEnum.Current : null;
while( hasMore )
{
string token = nextToken;
hasMore = tokensEnum.MoveNext();
nextToken = hasMore ? ( string ) tokensEnum.Current : null;
// the begin or end "'" has been found
if( "'".Equals( token ) )
{
quoted = !quoted;
}
if( quoted || char.IsWhiteSpace( token[ 0 ] ) )
{
result.Append( token );
}
else
{
bool isIdentifier = token[ 0 ] == '`' || ( // allow any identifier quoted with backtick
Char.IsLetter( token[ 0 ] ) && // only recognizes identifiers beginning with a letter
!Keywords.Contains( token.ToLower( System.Globalization.CultureInfo.InvariantCulture ) ) &&
token.IndexOf( '.' ) < 0
);
if( afterFrom )
{
result.Append( token );
afterFrom = false;
afterFromTable = true;
}
else if( afterFromTable )
{
afterFromTable = false;
result.Append( token );
}
else if( isIdentifier && ( nextToken == null || !nextToken.Equals( "(" ) ) ) // not a function call
{
result.Append( Placeholder )
.Append( StringHelper.Dot )
.Append( Quote( token, dialect ) );
}
else
{
if( "from".Equals( token.ToLower( System.Globalization.CultureInfo.InvariantCulture ) ) )
{
afterFrom = true;
}
result.Append( token );
}
}
}
return result.ToString();
}
示例12: RenderOrderByStringTemplate
/// <summary>
/// Takes "order by" clause in the mapping attribute and iterpolates the alias
/// </summary>
/// <param name="orderBySql">The "order by" sql statement from the mapping.</param>
/// <param name="dialect">The <see cref="Dialect.Dialect"/> to help with rendering the Sql.</param>
/// <returns>
/// A well formed "order by" sql statement for the <see cref="Dialect.Dialect"/>.
/// </returns>
public static string RenderOrderByStringTemplate( string orderBySql, Dialect.Dialect dialect )
{
//TODO: make this a bit nicer
StringTokenizer tokens = new StringTokenizer( orderBySql, ",", false );
StringBuilder result = new StringBuilder( orderBySql.Length + 2 );
bool commaNeeded = false;
IEnumerator tokenEnum = tokens.GetEnumerator();
while( tokenEnum.MoveNext() )
{
string column = Quote( ( ( string ) tokenEnum.Current ).Trim(), dialect );
if( commaNeeded )
{
result.Append( StringHelper.CommaSpace );
}
commaNeeded = true;
result.Append( Placeholder )
.Append( StringHelper.Dot )
.Append( column );
}
return result.ToString();
}
示例13: InitParameterBookKeeping
private void InitParameterBookKeeping()
{
StringTokenizer st = new StringTokenizer( queryString, ParserHelper.HqlSeparators, true );
ISet result = new HashedSet();
IEnumerator enumer = st.GetEnumerator();
while( enumer.MoveNext() )
{
string str = (string) enumer.Current;
if ( str.StartsWith( ParserHelper.HqlVariablePrefix ) )
{
result.Add( str.Substring( 1 ) );
}
}
actualNamedParameters = result;
// TODO: This is weak as it doesn't take account of ? embedded in the SQL
positionalParameterCount = StringHelper.CountUnquoted( queryString, StringHelper.SqlParameter.ToCharArray()[0] );
}