PeekChar() public method

public PeekChar ( ) : char
return char
コード例 #1
0
ファイル: Json.cs プロジェクト: Stoom/KeePass
        public JsonArray(CharStream csDataSource)
        {
            if(csDataSource == null) throw new ArgumentNullException("csDataSource");

            char chInit = csDataSource.ReadChar(true);
            if(chInit != '[') throw new JsonFormatException();

            List<JsonValue> lValues = new List<JsonValue>();

            while(true)
            {
                char chNext = csDataSource.PeekChar(true);
                if(chNext == ']') break;

                lValues.Add(new JsonValue(csDataSource));

                chNext = csDataSource.PeekChar(true);
                if(chNext == ',') csDataSource.ReadChar(true);
            }

            char chTerminator = csDataSource.ReadChar(true);
            if(chTerminator != ']') throw new JsonFormatException();

            m_values = lValues.ToArray();
        }
コード例 #2
0
ファイル: Json.cs プロジェクト: ComradeP/KeePass-2.x
		public JsonObject(CharStream csDataSource)
		{
			if(csDataSource == null) throw new ArgumentNullException("csDataSource");

			char chInit = csDataSource.ReadChar(true);
			if(chInit != '{') throw new JsonFormatException();

			while(true)
			{
				string strName = (new JsonString(csDataSource)).Value;

				char chSeparator = csDataSource.ReadChar(true);
				if(chSeparator != ':') throw new JsonFormatException();

				JsonValue jValue = new JsonValue(csDataSource);

				m_dict[strName] = jValue;

				char chNext = csDataSource.PeekChar(true);
				if(chNext == '}') break;
				else if(chNext == ',') csDataSource.ReadChar(true);
				else throw new JsonFormatException();
			}

			char chTerminator = csDataSource.ReadChar(true);
			if(chTerminator != '}') throw new JsonFormatException();
		}
コード例 #3
0
		public override void Import(PwDatabase pwStorage, Stream sInput,
			IStatusLogger slLogger)
		{
			StreamReader sr = new StreamReader(sInput, Encoding.UTF8);
			string strContent = sr.ReadToEnd();
			sr.Close();

			if(strContent.Length == 0) return;

			CharStream cs = new CharStream(strContent);

			JsonObject jRoot = new JsonObject(cs);
			AddObject(pwStorage.RootGroup, jRoot, pwStorage, false);
			Debug.Assert(cs.PeekChar(true) == char.MinValue);
		}
コード例 #4
0
		public override void Import(PwDatabase pwStorage, Stream sInput,
			IStatusLogger slLogger)
		{
			StreamReader sr = new StreamReader(sInput, StrUtil.Utf8);
			string strContent = sr.ReadToEnd();
			sr.Close();

			if(string.IsNullOrEmpty(strContent)) return;

			CharStream cs = new CharStream(strContent);

			Dictionary<string, List<string>> dTags =
				new Dictionary<string, List<string>>();
			List<PwEntry> lCreatedEntries = new List<PwEntry>();

			JsonObject jRoot = new JsonObject(cs);
			AddObject(pwStorage.RootGroup, jRoot, pwStorage, false, dTags,
				lCreatedEntries);
			Debug.Assert(cs.PeekChar(true) == char.MinValue);

			// Assign tags
			foreach(PwEntry pe in lCreatedEntries)
			{
				string strUri = pe.Strings.ReadSafe(PwDefs.UrlField);
				if(strUri.Length == 0) continue;

				foreach(KeyValuePair<string, List<string>> kvp in dTags)
				{
					foreach(string strTagUri in kvp.Value)
					{
						if(strUri.Equals(strTagUri, StrUtil.CaseIgnoreCmp))
							pe.AddTag(kvp.Key);
					}
				}
			}
		}
コード例 #5
0
ファイル: Json.cs プロジェクト: ComradeP/KeePass-2.x
		public JsonNumber(CharStream csDataSource)
		{
			if(csDataSource == null) throw new ArgumentNullException("csDataSource");

			StringBuilder sb = new StringBuilder();
			while(true)
			{
				char ch = csDataSource.PeekChar(true);

				if(((ch >= '0') && (ch <= '9')) || (ch == 'e') || (ch == 'E') ||
					(ch == '+') || (ch == '-') || (ch == '.'))
				{
					csDataSource.ReadChar(true);
					sb.Append(ch);
				}
				else break;
			}

			if(!double.TryParse(sb.ToString(), out m_value)) { Debug.Assert(false); }
		}
コード例 #6
0
ファイル: Json.cs プロジェクト: ComradeP/KeePass-2.x
		public JsonValue(CharStream csDataSource)
		{
			if(csDataSource == null) throw new ArgumentNullException("csDataSource");

			char chNext = csDataSource.PeekChar(true);

			if(chNext == '\"') m_value = (new JsonString(csDataSource)).Value;
			else if(chNext == '{') m_value = new JsonObject(csDataSource);
			else if(chNext == '[') m_value = new JsonArray(csDataSource);
			else if(chNext == 't')
			{
				for(int i = 0; i < 4; ++i) csDataSource.ReadChar(true);
				m_value = true;
			}
			else if(chNext == 'f')
			{
				for(int i = 0; i < 5; ++i) csDataSource.ReadChar(true);
				m_value = false;
			}
			else if(chNext == 'n')
			{
				for(int i = 0; i < 4; ++i) csDataSource.ReadChar(true);
				m_value = null;
			}
			else m_value = new JsonNumber(csDataSource);
		}
コード例 #7
0
ファイル: Json.cs プロジェクト: Stoom/KeePass
        public JsonNumber(CharStream csDataSource)
        {
            if(csDataSource == null) throw new ArgumentNullException("csDataSource");

            StringBuilder sb = new StringBuilder();
            while(true)
            {
                char ch = csDataSource.PeekChar(true);

                if(((ch >= '0') && (ch <= '9')) || (ch == 'e') || (ch == 'E') ||
                    (ch == '+') || (ch == '-') || (ch == '.'))
                {
                    csDataSource.ReadChar(true);
                    sb.Append(ch);
                }
                else break;
            }

            const NumberStyles ns = (NumberStyles.Integer | NumberStyles.AllowDecimalPoint |
                NumberStyles.AllowThousands | NumberStyles.AllowExponent);
            if(!double.TryParse(sb.ToString(), ns, NumberFormatInfo.InvariantInfo,
                out m_value)) { Debug.Assert(false); }
        }
コード例 #8
0
ファイル: SendInputEx.cs プロジェクト: rdealexb/keepass
        private static List<SiEvent> ParseSpecial(CharStream cs)
        {
            // Skip leading white space
            while(true)
            {
                char ch = cs.PeekChar();
                if(ch == char.MinValue) { Debug.Assert(false); return null; }

                if(!char.IsWhiteSpace(ch)) break;
                cs.ReadChar();
            }

            // First char is *always* part of the name (support for "{{}", etc.)
            char chFirst = cs.ReadChar();
            if(chFirst == char.MinValue) { Debug.Assert(false); return null; }

            int iPart = 0;
            StringBuilder sbName = new StringBuilder(), sbParams =
                new StringBuilder();
            sbName.Append(chFirst);

            while(true)
            {
                char ch = cs.ReadChar();
                if(ch == char.MinValue) { Debug.Assert(false); return null; }
                if(ch == '}') break;

                if(iPart == 0)
                {
                    if(char.IsWhiteSpace(ch)) ++iPart;
                    else sbName.Append(ch);
                }
                else sbParams.Append(ch);
            }

            string strName = sbName.ToString();
            string strParams = sbParams.ToString().Trim();

            uint? ouParam = null;
            if(strParams.Length > 0)
            {
                uint uParamTry;
                if(uint.TryParse(strParams, out uParamTry)) ouParam = uParamTry;
            }

            List<SiEvent> l = new List<SiEvent>();

            if(strName.Equals("DELAY", StrUtil.CaseIgnoreCmp))
            {
                if(!ouParam.HasValue) { Debug.Assert(false); return null; }

                SiEvent si = new SiEvent();
                si.Type = SiEventType.Delay;
                si.Delay = ouParam.Value;

                l.Add(si);
                return l;
            }
            if(strName.StartsWith("DELAY=", StrUtil.CaseIgnoreCmp))
            {
                SiEvent si = new SiEvent();
                si.Type = SiEventType.SetDefaultDelay;

                string strDelay = strName.Substring(6).Trim();
                uint uDelay;
                if(uint.TryParse(strDelay, out uDelay))
                    si.Delay = uDelay;
                else { Debug.Assert(false); return null; }

                l.Add(si);
                return l;
            }
            if(strName.Equals("VKEY", StrUtil.CaseIgnoreCmp) ||
                strName.Equals("VKEY-NX", StrUtil.CaseIgnoreCmp) ||
                strName.Equals("VKEY-EX", StrUtil.CaseIgnoreCmp))
            {
                if(!ouParam.HasValue) { Debug.Assert(false); return null; }

                SiEvent si = new SiEvent();
                si.Type = SiEventType.Key;
                si.VKey = (int)ouParam.Value;

                if(strName.EndsWith("-NX", StrUtil.CaseIgnoreCmp))
                    si.ExtendedKey = false;
                else if(strName.EndsWith("-EX", StrUtil.CaseIgnoreCmp))
                    si.ExtendedKey = true;

                l.Add(si);
                return l;
            }
            if(strName.Equals("APPACTIVATE", StrUtil.CaseIgnoreCmp))
            {
                SiEvent si = new SiEvent();
                si.Type = SiEventType.AppActivate;
                si.Text = strParams;

                l.Add(si);
                return l;
            }

            SiCode siCode = SiCodes.Get(strName);

            SiEvent siTmpl = new SiEvent();
            if(siCode != null)
            {
                siTmpl.Type = SiEventType.Key;
                siTmpl.VKey = siCode.VKey;
                siTmpl.ExtendedKey = siCode.ExtKey;
            }
            else if(strName.Length == 1)
            {
                siTmpl.Type = SiEventType.Char;
                siTmpl.Char = strName[0];
            }
            else
            {
                throw new FormatException(KPRes.AutoTypeUnknownPlaceholder +
                    MessageService.NewLine + @"{" + strName + @"}");
            }

            uint uRepeat = 1;
            if(ouParam.HasValue) uRepeat = ouParam.Value;

            for(uint u = 0; u < uRepeat; ++u)
            {
                SiEvent si = new SiEvent();
                si.Type = siTmpl.Type;
                si.VKey = siTmpl.VKey;
                si.ExtendedKey = siTmpl.ExtendedKey;
                si.Char = siTmpl.Char;

                l.Add(si);
            }

            return l;
        }