bool GetVersionValue(int startPropertyIndex, out VersionOccurrence v)
        {
            v = null;
            Matcher.MatchWhiteSpaces(0);
            string version;

            if (!Matcher.TryMatchJSONQuotedString(out version))
            {
                return(Matcher.SetError("Version string expected."));
            }
            int end = Matcher.StartIndex;

            Matcher.MatchWhiteSpaces(0);
            bool comma = Matcher.Head == ',';

            if (comma)
            {
                end = Matcher.StartIndex + 1;
            }
            v = new VersionOccurrence(version, startPropertyIndex, end - startPropertyIndex, comma);
            if (_versions != null)
            {
                CollectVersion(v);
            }
            return(true);
        }
Exemple #2
0
 public override bool VisitObjectProperty( int startPropertyIndex, string propertyName, int propertyIndex )
 {
     if( Path.Count == 0 )
     {
         _hasTopLevelProperties = true;
         if( propertyName == "version" )
         {
             if( _thisVersion != null ) return Matcher.SetError( "Duplicate version." );
             return GetVersionValue( startPropertyIndex, out _thisVersion );
         }
     }
     else if( _versions != null && Path[Path.Count-1].PropertyName == "dependencies" && _projectNameFinder( propertyName ) )
     {
         Matcher.MatchWhiteSpaces( 0 );
         if( Matcher.Head == '{' )
         {
             JSONVersionFinder f = new JSONVersionFinder( Matcher, null, null );
             if( f.ThisVersion == null ) return Matcher.SetError( "Property version expected." );
             CollectVersion( f.ThisVersion );
         }
         else
         {
             int start = Matcher.StartIndex;
             string version;
             if( !Matcher.TryMatchJSONQuotedString( out version ) ) return Matcher.SetError( "Version string expected." );
             VersionOccurrence v = new VersionOccurrence( version, start, Matcher.StartIndex - start, false );
             Debug.Assert( v.IsNakedVersionNumber );
             CollectVersion( v );
         }
         return true;
     }
     return base.VisitObjectProperty( startPropertyIndex, propertyName, propertyIndex );
 }
 void CollectVersion(VersionOccurrence v)
 {
     Debug.Assert(_versions != null && v != null);
     if (_versions.Count > 0)
     {
         _diffVersions |= _versions[0].Version != v.Version;
     }
     _versions.Add(v);
 }
        void ExtractVersions(string text)
        {
            StringMatcher     m           = new StringMatcher(text);
            var               allVersions = new List <VersionOccurrence>();
            JSONVersionFinder finder      = new JSONVersionFinder(m, _projectNameFinder, allVersions);

            _thisVersion  = finder.ThisVersion;
            _allVersions  = allVersions;
            _sameVersions = finder.SameVersions;
            _parseError   = m.ErrorMessage;
        }
Exemple #5
0
 public JSONVersionFinder( StringMatcher m, Func<string,bool> projectNameFinder, List<VersionOccurrence> allVersions )
     : base( m )
 {
     _objectStart = -1;
     _versions = allVersions;
     _projectNameFinder = projectNameFinder;
     if( Visit() )
     {
         if( _thisVersion == null && _objectStart >= 0 )
         {
             _thisVersion = new VersionOccurrence( String.Empty, _objectStart, 0, _hasTopLevelProperties );
             if( _versions != null ) _versions.Insert( 0, _thisVersion );
         }
     }
     if( _thisVersion == null && _versions != null ) _versions.Clear();
 }
 public override bool VisitObjectProperty(int startPropertyIndex, string propertyName, int propertyIndex)
 {
     if (Path.Count == 0)
     {
         _hasTopLevelProperties = true;
         if (propertyName == "version")
         {
             if (_thisVersion != null)
             {
                 return(Matcher.SetError("Duplicate version."));
             }
             return(GetVersionValue(startPropertyIndex, out _thisVersion));
         }
     }
     else if (_versions != null && Path[Path.Count - 1].PropertyName == "dependencies" && _projectNameFinder(propertyName))
     {
         Matcher.MatchWhiteSpaces(0);
         if (Matcher.Head == '{')
         {
             JSONVersionFinder f = new JSONVersionFinder(Matcher, null, null);
             if (f.ThisVersion == null)
             {
                 return(Matcher.SetError("Property version expected."));
             }
             CollectVersion(f.ThisVersion);
         }
         else
         {
             int    start = Matcher.StartIndex;
             string version;
             if (!Matcher.TryMatchJSONQuotedString(out version))
             {
                 return(Matcher.SetError("Version string expected."));
             }
             VersionOccurrence v = new VersionOccurrence(version, start, Matcher.StartIndex - start, false);
             Debug.Assert(v.IsNakedVersionNumber);
             CollectVersion(v);
         }
         return(true);
     }
     return(base.VisitObjectProperty(startPropertyIndex, propertyName, propertyIndex));
 }
 public JSONVersionFinder(StringMatcher m, Func <string, bool> projectNameFinder, List <VersionOccurrence> allVersions)
     : base(m)
 {
     _objectStart       = -1;
     _versions          = allVersions;
     _projectNameFinder = projectNameFinder;
     if (Visit())
     {
         if (_thisVersion == null && _objectStart >= 0)
         {
             _thisVersion = new VersionOccurrence(String.Empty, _objectStart, 0, _hasTopLevelProperties);
             if (_versions != null)
             {
                 _versions.Insert(0, _thisVersion);
             }
         }
     }
     if (_thisVersion == null && _versions != null)
     {
         _versions.Clear();
     }
 }
        /// <summary>
        /// Checks whether the two files are equal regardless of the "version: "" property.
        /// Line endings must be normalized (or be the same) for this to work correctly.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns><c>true</c> if files are the same or differ only by their version, <c>false</c> otherwise.</returns>
        public bool EqualsWithoutVersion(ProjectFileContent other)
        {
            // This ensures that ExtractVersion has been called.
            if ((Version != null) != (other.Version != null))
            {
                return(false);
            }
            if (_thisVersion == null)
            {
                return(_text == other._text);
            }
            if (_allVersions.Count != other._allVersions.Count)
            {
                return(false);
            }
            int last = 0, oLast = 0;

            for (int i = 0; i < _allVersions.Count; ++i)
            {
                VersionOccurrence o  = _allVersions[i];
                VersionOccurrence oo = other._allVersions[i];
                int lenBefore        = o.Start - last;
                if (lenBefore != (oo.Start - oLast) ||
                    string.Compare(_text, last, other._text, oLast, lenBefore, StringComparison.Ordinal) != 0)
                {
                    return(false);
                }
                last  = o.End;
                oLast = oo.End;
            }
            int lenAfter = _text.Length - last;

            if (lenAfter != (other._text.Length - oLast) ||
                string.Compare(_text, last, other._text, oLast, lenAfter, StringComparison.Ordinal) != 0)
            {
                return(false);
            }
            return(true);
        }
Exemple #9
0
 bool GetVersionValue( int startPropertyIndex, out VersionOccurrence v )
 {
     v = null;
     Matcher.MatchWhiteSpaces( 0 );
     string version;
     if( !Matcher.TryMatchJSONQuotedString( out version ) ) return Matcher.SetError( "Version string expected." );
     int end = Matcher.StartIndex;
     Matcher.MatchWhiteSpaces( 0 );
     bool comma = Matcher.Head == ',';
     if( comma ) end = Matcher.StartIndex + 1;
     v = new VersionOccurrence( version, startPropertyIndex, end - startPropertyIndex, comma );
     if( _versions != null ) CollectVersion( v );
     return true;
 }
Exemple #10
0
 void CollectVersion( VersionOccurrence v )
 {
     Debug.Assert( _versions != null && v != null );
     if( _versions.Count > 0 )
     {
         _diffVersions |= _versions[0].Version != v.Version;
     }
     _versions.Add( v );
 }
Exemple #11
0
 void ExtractVersions( string text )
 {
     StringMatcher m = new StringMatcher( text );
     var allVersions = new List<VersionOccurrence>();
     JSONVersionFinder finder = new JSONVersionFinder( m, _projectNameFinder, allVersions );
     _thisVersion = finder.ThisVersion;
     _allVersions = allVersions;
     _sameVersions = finder.SameVersions;
     _parseError = m.ErrorMessage;
 }