Example #1
0
        private static String checkPathVar(VarLabel varLabel, String ret)
        {
            if (strUtil.IsNullOrEmpty(ret))
            {
                return(ret);
            }

            if (varLabel.Prefix == "~" || varLabel.Prefix == "~/")
            {
                //if (ret.StartsWith( "/" )) {
                //    ret = ret.TrimStart( '/' );
                //}

                // ~img/,~js/, ~static/...只允许26个英文字母
                for (int i = 0; i < ret.Length; i++)
                {
                    if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(ret[i]) < 0)
                    {
                        return(null);
                    }
                }

                return(ret);
            }
            return(ret);
        }
Example #2
0
 private static Boolean getIsStartWithPrefix(VarLabel varLabel, char[] charList, int index)
 {
     for (int i = 0; i < varLabel.Prefix.Length; i++)
     {
         if (charList[index + i] != varLabel.Prefix[i])
         {
             return(false);
         }
     }
     return(true);
 }
Example #3
0
        private static String getStringToCheck(VarLabel varLabel, int index, char[] charList)
        {
            String strToCheck = "";
            int    maxLength  = getCheckMaxLength(varLabel);

            for (int i = varLabel.Prefix.Length; i < maxLength; i++)
            {
                if (index + i > charList.Length - 1)
                {
                    break;
                }
                strToCheck += charList[index + i];
            }

            return(strToCheck);
        }
Example #4
0
        private static String getMatchedVarName(VarLabel varLabel, int index, char[] charList)
        {
            // 1、是否以prefix开头
            Boolean isStartWithPrefix = getIsStartWithPrefix(varLabel, charList, index);

            if (!isStartWithPrefix)
            {
                return(null);
            }

            // 2、是否以postfix结尾

            String strToCheck   = getStringToCheck(varLabel, index, charList);
            int    postfixIndex = strToCheck.IndexOf(varLabel.Postfix);

            if (postfixIndex >= 0)
            {
                // 注意,这里可能返回String.Empty
                return(strToCheck.Substring(0, postfixIndex));
            }

            return(null);
        }
Example #5
0
        private static String getStringToCheck( VarLabel varLabel, int index, char[] charList )
        {
            String strToCheck = "";
            int maxLength = getCheckMaxLength( varLabel );
            for (int i = varLabel.Prefix.Length; i < maxLength; i++) {
                if (index + i > charList.Length - 1) break;
                strToCheck += charList[index + i];
            }

            return strToCheck;
        }
Example #6
0
        private static String getMatchedVarName( VarLabel varLabel, int index, char[] charList )
        {
            // 1、是否以prefix开头
            Boolean isStartWithPrefix = getIsStartWithPrefix( varLabel, charList, index );
            if (!isStartWithPrefix) return null;

            // 2、是否以postfix结尾

            String strToCheck = getStringToCheck( varLabel, index, charList );
            int postfixIndex = strToCheck.IndexOf( varLabel.Postfix );
            if (postfixIndex >= 0) {
                // 注意,这里可能返回String.Empty
                return strToCheck.Substring( 0, postfixIndex );
            }

            return null;
        }
Example #7
0
 private static Boolean getIsStartWithPrefix( VarLabel varLabel, char[] charList, int index )
 {
     for (int i = 0; i < varLabel.Prefix.Length; i++) {
         if (charList[index + i] != varLabel.Prefix[i]) return false;
     }
     return true;
 }
Example #8
0
 private static int getCheckMaxLength( VarLabel varLabel )
 {
     return varLabel.Prefix.Length + 50;
 }
Example #9
0
 private static int getCheckMaxLength(VarLabel varLabel)
 {
     return(varLabel.Prefix.Length + 50);
 }
Example #10
0
        private static String checkPathVar( VarLabel varLabel, String ret )
        {
            if (strUtil.IsNullOrEmpty( ret )) return ret;

            if (varLabel.Prefix == "~" || varLabel.Prefix == "~/") {

                //if (ret.StartsWith( "/" )) {
                //    ret = ret.TrimStart( '/' );
                //}

                // ~img/,~js/, ~static/...只允许26个英文字母
                for (int i = 0; i < ret.Length; i++) {
                    if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf( ret[i] ) < 0) {
                        return null;
                    }
                }

                return ret;

            }
            return ret;
        }