Package org.jostraca.util

Examples of org.jostraca.util.RegExp


        includeBlockMatch = allincludeblocks[ includeBlockI ];
        includeBlockText  = includeBlockMatch.match();
        includeBlockFile  = includeBlockMatch.matchFirstSub();
        includeBlockMark  = includeBlockMatch.matchSecondSub();

        RegExp markRegExp = RegExp.make( includeBlockMark, RegExp.ModeSet.DotMatchesNewline );

        // include the file block
        String  includeFileContent  = FileUtil.readFile( pIncludeBase + File.separatorChar + includeBlockFile );       
        String  includeBlockContent = markRegExp.match( includeFileContent );

        // very important - prevent data loss
        if( Standard.EMPTY.equals( includeBlockContent ) ) {
          throw new TemplateException( TemplateException.CODE_includeblock_find,
                                       new ValueSet( ValueCode.FILE, includeBlockFile, ValueCode.VALUE, includeBlockMark ) );
View Full Code Here


  protected void parseOutResult( String pOutResult, Template pTemplate ) {
    Vector savedFilesV = new Vector();

    try {
      RegExp        savedFileRE = RegExp.make( "Saved\\s+file:\\s*(.*?)\r?\n" );
      RegExpMatch[] mA          = savedFileRE.matchAll( pOutResult );
      int           numM        = mA.length;
      for( int mI = 0; mI < numM; mI++ ) {
        RegExpMatch m = mA[mI];
        String      savedFile = m.matchSub(1);
        savedFilesV.addElement( savedFile );
View Full Code Here



  public void doReplaceRegExpTests( RegExpProvider pREP ) throws Exception {

    RegExp re01 = pREP.make( "a", "b" );
    assertEquals( "b",  re01.replaceAll( "a" ) );
    assertEquals( "bb", re01.replaceAll( "aa" ) );
    assertEquals( "ba", re01.replaceFirst( "aa" ) );
    assertEquals( "xb", re01.replaceFirst( "xa" ) );

    RegExp re02 = pREP.make( "a" );
    assertEquals( "",  re02.replaceAll( "a" ) );
   
    try {
      RegExp re03 = pREP.make( "*" );
      fail();
    }
    catch( RegExpException ree ) {
      //System.out.println( ree );
    }

    RegExp re04 = pREP.make( "a(b+)c", "ca$1" );
    assertEquals( "cabbbabbbc", re04.replaceFirst( "abbbcabbbc" ) );

    RegExp re05 = pREP.make( "A", "b", new RegExp.ModeSet( RegExp.Mode.CaseInsensitive ) );
    assertEquals( "bbc", re05.replaceFirst( "abc" ) );

    RegExp re06 = pREP.make( "A.", "b", new RegExp.ModeSet( RegExp.Mode.CaseInsensitive, RegExp.Mode.DotMatchesNewline ) );
    assertEquals( "bbc", re06.replaceFirst( "a\nbc" ) );
  }
View Full Code Here

    assertEquals( "bbc", re06.replaceFirst( "a\nbc" ) );
  }


  public void doMatchRegExpTests( RegExpProvider pREP ) throws Exception {
    RegExp re01 = pREP.make( "a(.*?)c" );
    assertEquals( "abc",  re01.match( "abcc" ) );
    assertEquals( "b",    re01.matchFirstSub( "abcc" ) );

    RegExp re02 = pREP.make( "\\$a" );
    assertEquals( "$a",  re02.match( "$ab" ) );

    RegExp re03 = pREP.make( "a.b.", new RegExp.ModeSet( RegExp.Mode.DotMatchesNewline ) );
    assertEquals( "a\nb\n",  re03.match( "ca\nb\n" ) );

    RegExp re04 = pREP.make( "^[ \\t]*\\n(.*)", new RegExp.ModeSet( RegExp.Mode.DotMatchesNewline ) );
    assertEquals( "b\n",  re04.matchFirstSub( "\nb\n" ) );
  }
View Full Code Here

    assertEquals( "b\n",  re04.matchFirstSub( "\nb\n" ) );
  }


  public void doMatchAllTests( RegExpProvider pREP ) throws Exception {
    RegExp      re01 = pREP.make( "a(.)\n" );
    RegExpMatch m[]  = re01.matchAll( "x\naa\nab\nac\ny\n" );
    assertEquals( 3, m.length );
    assertEquals( "aa\n", m[0].match() );
    assertEquals( "ab\n", m[1].match() );
    assertEquals( "ac\n", m[2].match() );
    assertEquals( "a", m[0].matchSub(1) );
View Full Code Here

  protected void parseOutResult( String pOutResult, Template pTemplate ) {
    Vector savedFilesV = new Vector();

    try {
      RegExp        savedFileRE = RegExp.make( "Saved\\s+file:\\s*(.*?)\r?\n" );
      RegExpMatch[] mA          = savedFileRE.matchAll( pOutResult );
      int           numM        = mA.length;
      for( int mI = 0; mI < numM; mI++ ) {
        RegExpMatch m = mA[mI];
        String      savedFile = m.matchSub(1);
        savedFilesV.addElement( savedFile );
View Full Code Here

    String nonStatementLineRegExpDef = pPropertySet.get( PropertyPython.nonStatementLineRegExp );
    String controlFlowRegExpDef      = pPropertySet.get( PropertyPython.controlFlowRegExp );
    String pythonInsertPrefix        = pPropertySet.get( Property.lang_InsertPrefix );

    // create regexps
    RegExp nonStatementLineRegExp = null;
    try {
      nonStatementLineRegExp = RegExp.make( nonStatementLineRegExpDef );
    } catch( RegExpException ree ) {
      throw new ModifierException( "Unable to understand regular expression for matching non statement lines: "+
                                   PropertyPython.nonStatementLineRegExp+"="+nonStatementLineRegExpDef
                                   );
    }

    RegExp controlFlowRegExp      = null;
    try {
      controlFlowRegExp      = RegExp.make( controlFlowRegExpDef );
    } catch( RegExpException ree ) {
      throw new ModifierException( "Unable to understand regular expression for matching control flow lines: "+
                                   PropertyPython.controlFlowRegExp+"="+controlFlowRegExpDef
View Full Code Here

      boolean onlyifexists = pArguments.contains( INCLUDE_MOD_if_exists );

      String includeFileContent = FileUtil.readFile( includeFilePath, ( onlyifexists ? FileUtil.EMPTY_IF_IO_ERROR : FileUtil.FAIL_ON_IO_ERROR ) );
      String includeBlockMark = (String) pArguments.get(0);
     
      RegExp markRegExp = RegExp.make( includeBlockMark, RegExp.ModeSet.DotMatchesNewline );
      String includeBlockContent = markRegExp.match( includeFileContent );

      return includeBlockContent;
    }
    catch( Exception e ) {
      throw new TemplateException( TemplateException.CODE_includeblock,
View Full Code Here

TOP

Related Classes of org.jostraca.util.RegExp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.