ExtractInfo.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpers » ExtractInfo.cs
using System;

namespace FileHelpers{

  internal sealed class ExtractedInfo
  {
    //public int CharsRemoved;
    //public string ExtractedString;

    internal string mCustomExtractedString = null;

    public string ExtractedString()
    {
      if (mCustomExtractedString == null)
        return new string(mLine.mLine, ExtractedFrom, ExtractedTo - ExtractedFrom + 1);
      else
        return mCustomExtractedString;
      //      return new string(mLine,  .mLine.Substring(ExtractedFrom, ExtractedTo - ExtractedFrom + 1);

    }

    public int Length
    {
      get { return ExtractedTo - ExtractedFrom + 1;}
    }

    public LineInfo mLine;
    public int ExtractedFrom;
    public int ExtractedTo;

    //public int ExtraLines;
    //public string NewRestOfLine;
    //public string TrailString;

    public ExtractedInfo(LineInfo line)
    {
      mLine = line;
      ExtractedFrom = line.mCurrentPos;
      ExtractedTo = line.mLine.Length - 1;
      //CharsRemoved = ExtractedTo - ExtractedFrom + 1;
      //ExtraLines = 0;
    //  NewRestOfLine = null;
    }

    public ExtractedInfo(LineInfo line, int extractTo)
    {
      mLine = line;
      ExtractedFrom = line.mCurrentPos;
      ExtractedTo = extractTo - 1;
      //CharsRemoved = ExtractedTo - ExtractedFrom + 1;
      //ExtraLines = 0;
    //  NewRestOfLine = null;
    }
    
    public ExtractedInfo(string customExtract)
    {
      mCustomExtractedString = customExtract;
    }
    
    public void TrimStart(char[] sortedToTrim)
    {
      if (mCustomExtractedString != null)
        mCustomExtractedString = mCustomExtractedString.TrimStart(sortedToTrim);
      else
        while(ExtractedFrom < ExtractedTo&& Array.BinarySearch(sortedToTrim, mLine.mLine[ExtractedFrom]) >= 0)
          ExtractedFrom++;
    }

    public void TrimEnd(char[] sortedToTrim)
    {
      if (mCustomExtractedString != null)
        mCustomExtractedString = mCustomExtractedString.TrimEnd(sortedToTrim);
      else
        while(ExtractedTo > ExtractedFrom && Array.BinarySearch(sortedToTrim, mLine.mLine[ExtractedTo]) >= 0)
          ExtractedTo--;
    }

    public void TrimBoth(char[] sortedToTrim)
    {
      if (mCustomExtractedString != null)
        mCustomExtractedString = mCustomExtractedString.Trim(sortedToTrim);
      else
      {
        while(ExtractedFrom <= ExtractedTo && Array.BinarySearch(sortedToTrim, mLine.mLine[ExtractedFrom]) >= 0)
        {
          ExtractedFrom++;
        }
      
        while(ExtractedTo > ExtractedFrom && Array.BinarySearch(sortedToTrim, mLine.mLine[ExtractedTo]) >= 0)
        {
          ExtractedTo--;
        }
      }
    }

    //
    //          public ExtractedInfo(string extracted, int charsRem, int lines)
    //          {
    //            ExtractedString = extracted;
    //            CharsRemoved = charsRem;
    //            ExtraLines = lines;
    //            NewRestOfLine = null;
    //          }

    internal static readonly ExtractedInfo Empty = new ExtractedInfo(string.Empty);

    public bool HasOnlyThisChars(char[] sortedArray)
    {
      // Check if the chars at pos or right are empty ones
      if (mCustomExtractedString != null)
      {
        int pos = 0;
        while ( pos <  mCustomExtractedString.Length && 
            Array.BinarySearch(sortedArray,  mCustomExtractedString[pos]) >= 0 )
        {
          pos++;
        }
      
        return pos == mCustomExtractedString.Length;
      }
      else
      {

        int pos = ExtractedFrom;
        while(pos <= ExtractedTo && Array.BinarySearch(sortedArray, mLine.mLine[pos]) >= 0)
        {
          pos++;
        }
      
        return pos > ExtractedTo;
      }
    }
  }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.