public CharWithType GetChar() { charType type = (charType)4; char charToReturn = availableChars[rnd.Next(availableChars.Length)]; foreach (charType t in types) { if (LOWERCASE.Contains(charToReturn)) { type = charType.lowerCase; break; } else if (UPPERCASE.Contains(charToReturn)) { type = charType.upperCase; break; } else if (SPECIAL.Contains(charToReturn)) { type = charType.special; break; } else if (NUMBER.Contains(charToReturn)) { type = charType.number; break; } } return(new CharWithType(charToReturn, type)); }
public static string divideSpace(string expr) { charType lastTok = charType.unknown; string result = ""; foreach (char c in expr) { if (char.IsSeparator(c)) { continue; } if (lastTok.Equals(IdentifyChar(c)) || lastTok.Equals(charType.unknown) ) { result += c; } else { result += " " + c; } lastTok = IdentifyChar(c); } return(result); }
private void InsertIntoPassword(charType type) { if (!EnoughOfType(type)) { password.Insert(rnd.Next(password.Length + 1), grc.GetChar(type)); } else { grc.RemoveType(type); } }
public static bool IsAnyOfTheseTypes(this charType ct, params charType[] types) { foreach (var type in types) { if (type == (ct & type)) { return(true); } } return(false); }
public char GetChar(charType type) { switch (type) { case charType.lowerCase: return(LOWERCASE[rnd.Next(LOWERCASE.Length)]); case charType.upperCase: return(UPPERCASE[rnd.Next(UPPERCASE.Length)]); case charType.special: return(SPECIAL[rnd.Next(SPECIAL.Length)]); case charType.number: return(NUMBER[rnd.Next(NUMBER.Length)]); default: throw new ArgumentOutOfRangeException(); } }
private bool EnoughOfType(charType type) { switch (type) { case charType.lowerCase: return(_lowerCaseMax != -1 && containsLowerCase.Matches(password.ToString()).Count >= _lowerCaseMax); case charType.upperCase: return(_upperCaseMax != -1 && containsUpperCase.Matches(password.ToString()).Count >= _upperCaseMax); case charType.special: return(_specialMax != -1 && containsSpecial.Matches(password.ToString()).Count >= _specialMax); case charType.number: return(_numberMax != -1 && containsNumber.Matches(password.ToString()).Count >= _numberMax); default: return(false); } }
public Notation() { type = charType.DAN; drawable = new List <Stroke>(); }
public CharWithType(char character, charType type) { this.character = character; this.type = type; }
public void RemoveType(charType type) { types.Remove(type); }
// get mass from formula string public float solveString(string input) { tempString = input.ToUpper() + "%"; // add the stop point int readIndex = 1; // record read position in this round float newMass = 0.0f; // temp for mass calculation charType tempCharType = getCharType(tempString[0]); //current read char type string block = null; // meaningful block for calculation do { readIndex = 0; do { block = tempString.Substring(0, readIndex + 1); //get current char block tempCharType = getCharType(tempString[readIndex]); //get current char type if (charType.Operator == tempCharType) { readIndex++; break; } if ((charType.Element == tempCharType) && (elementDictionary.ContainsKey(block))) // if block is recorded in dictionary { if (elementDictionary.ContainsKey(tempString.Substring(0, readIndex + 2))) // especially for case like both of Fe and F were registed { readIndex += 2; block = tempString.Substring(0, readIndex); break; } else { readIndex++; break; } } else if (charType.None == tempCharType) { Console.Write("Unsolveable symbol dectected!\n"); clearAll(); return(-1.0f); } } while (getCharType(tempString[++readIndex]) == tempCharType); // if the next char type same as current one? switch (tempCharType) { case charType.Element: if (elementDictionary.ContainsKey(block)) { operateNumberStack.Push(elementDictionary[block]); // if block is registed as element, push its mass to stack } else { clearAll(); //before return, clear data in stacks Console.Write("Can not find this element {0} in dictionary.\n", block); return(-1.0f); } break; case charType.Number: if (operateNumberStack.Count < 1) { Console.Write("Unsolveable Formula.\n"); // number should follow an element return(-1.0f); } newMass = operateNumberStack.Pop() * float.Parse(block); // calculate with the top of number stack operateNumberStack.Push(newMass); break; case charType.Operator: if (((')' == block[0]) && ('(' == operatorStack.Peek())) || (']' == block[0]) && ('[' == operatorStack.Peek())) { operatorStack.Pop(); sumStackTo(operatorIndex.Pop()); } else { operatorStack.Push(block[0]); operatorIndex.Push(operateNumberStack.Count); } break; default: break; } tempString = tempString.Substring(readIndex); } while (tempString.Length > 1); sumStackTo(0); Console.WriteLine("{0} = {1}", input, operateNumberStack.Peek()); operatorStack.Clear(); return(operateNumberStack.Pop()); }
public void Mutate(int type){ if (type == 0) { this.type = charType.PRIEST; movementSpeed = priestSpeed; acceleration = priestAcceleration; priestModel.SetActive (true); sheepModel.SetActive (false); body = priestModel; anim = priestAnim; } if (type == 1) { this.type = charType.SHEEP; movementSpeed = sheepSpeed; acceleration = sheepAcceleration; priestModel.SetActive (false); sheepModel.SetActive (true); body = sheepModel; anim = sheepAnim; LightningStrike (); } }
public static charType IsWhatType(this char c) { charType rv = (charType)0; switch (c) { case ('_'): return(charType.underscore | charType.validfirst4identifier | charType.validsecond4identifier | charType.letterordigitor_); case ('1'): case ('0'): return(charType.digit | charType.binarydigit | charType.hexdigit | charType.validsecond4identifier | charType.letterordigitor_ | charType.realnumberpart | charType.integerpart); case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': return(charType.hexdigit | charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.validfirst4identifier | charType.validsecond4identifier); case 'M': case 'm': return(charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.validfirst4identifier | charType.validsecond4identifier | charType.realnumberpart); case 'D': case 'd': case 'F': case 'f': return(charType.hexdigit | charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.validfirst4identifier | charType.validsecond4identifier | charType.realnumberpart); case 'E': case 'e': return(charType.exponent | charType.hexdigit | charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.validfirst4identifier | charType.validsecond4identifier | charType.realnumberpart); case '-': return(charType.minus | charType.operatordigit | charType.symbol | charType.realnumberpart | charType.integerpart | charType.symbol); case '(': case '[': case '{': return(charType.symbol | charType.opening | charType.declarationsyntax); case '<': return(charType.symbol | charType.opening | charType.declarationsyntax | charType.operatordigit); case ')': case ']': case '}': return(charType.symbol | charType.closing | charType.declarationsyntax); case '>': return(charType.symbol | charType.closing | charType.declarationsyntax | charType.operatordigit); case '"': case '\'': return(charType.symbol | charType.quote); case ';': case '\\': case '@': case '#': case '$': case ',': return(charType.punctuation | charType.symbol | charType.special); case '.': return(charType.punctuation | charType.symbol | charType.operatordigit | charType.realnumberpart); case 'U': case 'u': case 'L': case 'l': return(charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.integerpart); case ':': return(charType.punctuation | charType.symbol | charType.operatordigit | charType.declarationsyntax); case '?': return(charType.symbol | charType.operatordigit | charType.declarationsyntax); case '+': case '!': case '%': case '^': case '&': case '*': case '=': case '|': case '/': case '~': return(charType.symbol | charType.operatordigit); case '\uffff': return(charType.endoffile); } if (char.IsWhiteSpace(c)) { return(charType.whitespace); } if (char.IsDigit(c)) { return(charType.digit | charType.letterordigit | charType.letterordigitor_ | charType.validsecond4identifier); } if (char.IsLetter(c)) { return(charType.letter | charType.letterordigit | charType.letterordigitor_ | charType.validsecond4identifier | charType.validfirst4identifier); } throw new Exception($"Unrecognized character '{c}' value: {(int)c}"); }