Home

 

Examples

 

Technical

 TextMaestro"

 

2003 TextMaestro Technologies

 

Technical

1.

Introduction

2.

Main Toolbar

3.

Session Toolbar

4.

FTP Toolbar

5.

File Attributes

6.

Project Manager

7.

Account Manager

8.

Browse Remote
System

9.

Text Conversion Dialog

10.

Text Conversion Attributes

11.

Text Conversion Libraries

12.

Text Conversion Rules

13.

Text Conversion Batch Mode

14.

Text Conversion Command Line

15.

Report

16.

Diff-and-Merge

17.

Cross Listings

18.

Program Options

19.

Save Program Data

 

12. Text Conversion Rules

Find And Replace is the canonical form of conversion that we use in various text editors and integrated development environments. In TextMaestro, it attains a new level and thus incurs a small learning curve. It is so due to the power of wild-card and type-card usage. User defines a macro that consists of two parts - Find and Replace. The macro has certain attributes. This macro governs the conversion.

Here we discuss the following:

Usage

(1) Basic find-and-replace

(2) Use of wild-card

(2.1) Generic wild-card

(2.2) Special characteristics of wild-card

(2.2.1) Wild-card by itself

(2.2.2) Wild-card and line-break

(3) Use of type-card

Knobs

(1) Per-line search

(2) Compact construct

(3) Filter processed text

(4) Delimiter parse

Qualifiers

(a) Trim Argument

(b) Case Argument

(c) Clean Argument

(d) Align Argument

(e) Increment Argument

Comments

 

Usage         Top

(1) Basic find-and-replace:         Top

Consider the following input text:

Input

//---------------------------------------------------------

// Session info

//---------------------------------------------------------

CSession::CSession()

{

    m_CreateDir = "Yes";

    m_IsLoaded = "No";

}

Consider this macro:

Find:

//---------------------------------------------------------

// Session info

//---------------------------------------------------------

Replace:

/*

*  TextMaestro Technologies

*  Base constructor initialization of CSession

*/

With these definitions, we get the following output text:

Output

/*

*  TextMaestro Technologies

*  Base constructor initialization of CSession

*/

CSession::CSession()

{

    m_CreateDir = "Yes";

    m_IsLoaded = "No";

}

Definitions of Find and Replace may contain line breaks. Find can be case-insensitive.

 

(2) Use of wild-card:         Top

When you define a macro, either in Work Pad or Find-And-Replace Library, you may choose to check Use wild-card. If you do so, the scheme enters in a mode where wild-card and type-card dictate a 'grammar' based conversion.

 

(2.1) Generic wild-card:         Top

Concept of wild-card can be viewed as pattern-matching. Wild-card is a place holder for arbitrary text on the path of parsing. If the non-wild-card text combined with wild-card text is found in the input text, then the conversion recognizes it as a match. Consider the following input:

Input

void CSession::WriteSessionHeaderInfo(ofstream& temp_out, int s_ind)

{

    CString _t;

    temp_out << "SessionName="   <<  LPCTSTR(m_SessionName)<< ", ";

    temp_out << "Host="          <<  LPCTSTR(m_Host)       << ", ";

    temp_out << "HostType="      <<  LPCTSTR(m_HostType)   << ", ";

    temp_out << "User="          <<  LPCTSTR(m_User)       << ", ";

    temp_out << "RemoteDir="     <<  LPCTSTR(m_RemoteDir)  << ", ";

    temp_out << "LocalDir="      <<  LPCTSTR(m_LocalDir)   << ", ";

    temp_out << "SessionBox="    <<  LPCTSTR(m_SessionBox) << ", ";

    temp_out << "CreateDir="     <<  LPCTSTR(m_CreateDir)  << ", ";

}

Consider this macro:

Find:

"*="

Replace:

"*: "

With these definitions, we get the following output:

Output

void CSession::WriteSessionHeaderInfo(ofstream& temp_out, int s_ind)

{

    CString _t;

    temp_out << "SessionName: "   <<  LPCTSTR(m_SessionName)<< ", ";

    temp_out << "Host: "          <<  LPCTSTR(m_Host)       << ", ";

    temp_out << "HostType: "      <<  LPCTSTR(m_HostType)   << ", ";

    temp_out << "User: "          <<  LPCTSTR(m_User)       << ", ";

    temp_out << "RemoteDir: "     <<  LPCTSTR(m_RemoteDir)  << ", ";

    temp_out << "LocalDir: "      <<  LPCTSTR(m_LocalDir)   << ", ";

    temp_out << "SessionBox: "    <<  LPCTSTR(m_SessionBox) << ", ";

    temp_out << "CreateDir: "     <<  LPCTSTR(m_CreateDir)  << ", ";

}

 

After a " is found, the search keeps assimilating characters until it finds =. What it finds on the way, becomes argument denoted by * in Replace. That is to say, you can use wild-card in Replace as a place-holder of the argument constructed during parsing.

Consider the following macro:

Find:

"*"*<<*LPCTSTR(*)*<<*

Replace:

"<*1>" + <*4> + <*6>

If you match the wild-cards in Find for a certain line, you will notice that first, fourth and sixth wild-card denote some tokens of interest. So we use those wild-cards in Replace in the form of <*n>. Thus, we get this output:

Output

void CSession::WriteSessionHeaderInfo(ofstream& temp_out, int s_ind)

{

    CString _t;

    temp_out << "SessionName=" + m_SessionName +  ", ";

    temp_out << "Host=" + m_Host +  ", ";

    temp_out << "HostType=" + m_HostType +  ", ";

    temp_out << "User=" + m_User +  ", ";

    temp_out << "RemoteDir=" + m_RemoteDir +  ", ";

    temp_out << "LocalDir=" + m_LocalDir +  ", ";

    temp_out << "SessionBox=" + m_SessionBox +  ", ";

    temp_out << "CreateDir=" + m_CreateDir +  ", ";

}

 

Sometimes user might need to use "*" in Find and/or Replace as non-wild-card in a wild-card mode search. In that case, some other character, for example "@", "~", "#", etc. can be used to denote wild-card. When you define a find-and-replace macro from Work Pad or Find And Replace Library you have the option to specify the wild-card character. For above example, if you had specified wild-card flag as "@", the macro would look like this:

Find:

"@"@<<@LPCTSTR(@)@<<@

Replace:

"<@1>" + <@4> + <@6>

Wild-card is @

 

Consider the following input:

Input

InfoTech_01_Program.htm      im_tech_sess_man01.gif

InfoTech_02_ToolbarMain.htm  im_tech_sess_man02.gif

InfoTech_03_TBSession.htm    im_tech_sess_man03.gif

InfoTech_04_TBFtp.htm        im_tech_sess_man04.gif

Now consider the following macro:

Find:

* *

Replace:

* contains *

Here is the output:

Output

InfoTech_01_Program.htm contains      im_tech_sess_man01.gif

InfoTech_02_ToolbarMain.htm contains  im_tech_sess_man02.gif

InfoTech_03_TBSession.htm contains    im_tech_sess_man03.gif

InfoTech_04_TBFtp.htm contains        im_tech_sess_man04.gif

Note that in Replace you can have wild-card in non-ordinal form. In that case wild-cards in Replace are resolved in the order they are found. I.e., the first wild-card stands for the first argument, and the second wild-card, for the second argument, and so on. It is recommended that you specify wild-cards in Replace in ordinal format (<*n>) for clarity.

 

(2.2) Special characteristics of wild-card:         Top

There are a few special characteristics of wild-card usage. If you are not familiar with them, you might find some of the wild-card effects unexpected. Once familiar, those special characteristics rather become handy.

 

(2.2.1) Wild-card by itself:         Top

Find consisting of single wild-card denotes the whole line. Consider the following input:

Input

void CTextCvt::SetCurrentIndex()

{

    m_dnLibInd_TP = CStaticLibraryDlg::m_nLibInd_TP;

    m_dnLibInd_FR = CStaticLibraryDlg::m_nLibInd_FR;

    m_dnLibInd_KL = CStaticLibraryDlg::m_nLibInd_KL;

}

Consider the following macro:

Find:

*

Replace:

// *

Here is the output:

Output

// void CTextCvt::SetCurrentIndex()

// {

//     m_dnLibInd_TP = CStaticLibraryDlg::m_nLibInd_TP;

//     m_dnLibInd_FR = CStaticLibraryDlg::m_nLibInd_FR;

//     m_dnLibInd_KL = CStaticLibraryDlg::m_nLibInd_KL;

// }

On the other hand, Find consisting of double wild-cards denotes the whole input. With the following macro:

Find:

@@

Replace:

/*

-------------------------------------------------------

@@

-------------------------------------------------------

*/

we get the following output from the above input:

Output

/*

-------------------------------------------------------

void CTextCvt::SetCurrentIndex()

{

    m_dnLibInd_TP = CStaticLibraryDlg::m_nLibInd_TP;

    m_dnLibInd_FR = CStaticLibraryDlg::m_nLibInd_FR;

    m_dnLibInd_KL = CStaticLibraryDlg::m_nLibInd_KL;

}

-------------------------------------------------------

*/

Note that we had to switch to "@" for wild-card, since we used "*" as non-wild-card in Replace.

 

(2.2.2) Wild-card and line-break:         Top

Wild-card at the beginning of Find denotes text from the previous line-break. Consider the following macro.

Find:

*=

Replace:

// *=

From the same input above we get the following output:

Output

void CTextCvt::SetCurrentIndex()

{

//     m_dnLibInd_TP = CStaticLibraryDlg::m_nLibInd_TP;

//     m_dnLibInd_FR = CStaticLibraryDlg::m_nLibInd_FR;

//     m_dnLibInd_KL = CStaticLibraryDlg::m_nLibInd_KL;

}

 

In similar fashion, wild-card at the end of Find denotes text to the next line-break. Consider the following macro:

Find:

=*

Replace:

= 0; // *

which creates this output:

Output

void CTextCvt::SetCurrentIndex()

{

    m_dnLibInd_TP = 0; //  CStaticLibraryDlg::m_nLibInd_TP;

    m_dnLibInd_FR = 0; //  CStaticLibraryDlg::m_nLibInd_FR;

    m_dnLibInd_KL = 0; //  CStaticLibraryDlg::m_nLibInd_KL;

}

 

 

(3) Use of type-card:         Top

Similar to wild-card, there is a parallel concept of type-card. Type-card can be used only when Use wild-card is checked. Let us begin with an example. Consider the following input:

Input

Each  macro    you  define  can be     stored  in     a  library.

When    you    click  on   the convert   button from    the library

panel,   you  basically   execute   the  active  macros   of the

library   sequentially.    Using   a library   of macros  on an

input   is   a   whole    new   level   of    muscle  to  flex.

 

Note the occurrences of multiple blanks, which ideally should be just one blank. One or many consecutive blanks are denoted by ^b type-card. Consider the following macro:

Find:

^b

Replace:

(blank)

which gives the following output:

Output

Each macro you define can be stored in a library.

When you click on the convert button from the library

panel, you basically execute the active macros of the

library sequentially. Using a library of macros on an

input is a whole new level of muscle to flex.

 

By default, there are six kinds of type-cards per library:

 

When used in wild-card mode denotes:

 

^b

one or many consecutive blank spaces (' ' and/or tabs).

(Blank)

^n

one or many consecutive line-breaks (accepting blanks on the way).

(\n)

^a

one or many consecutive characters from a-z and A-Z sets.

(Alpha)

^d

one or many consecutive characters from 0-9 sets.

(Digit)

^m

one or many consecutive math operators: + - * / < > { } [ ] ( ) =

(math)

^p

one or more consecutive punctuation operators: , . : ; " '

(punctuation)

User can define his own set of type-cards using Wild-card Manager. See more.

Here are some examples. Consider the following input:

Input

Box05-Ses25-Get-Bld-92903.txt  10

Box05-Ses26-Importedtest.jpg  10

Box05-Ses27-Hypnos.gif  10

Box05-Ses28-Hypnos-Part.txt  11

Box05-Ses29-Hypnos-Linux-Build.txt 11

Box06-Ses30-Text-Pos.txt  12

Box07-Ses31-Inter-Dev.com  12

Box07-Ses32-Inter-Port.txt  12

Box07-Ses33-Test-Suit.txt  13

Box07-Ses34-Test-Match.bmp  14

Box07-Ses35-Test-New.txt  15

Consider this macro:

Find:

^a^d^m^a^d^m*.^a*^d

Replace:

   *.<^a3><a=30><^d3>

which gives the following output:

Output

   Get-Bld-92903.txt         10

   Importedtest.jpg          10

   Hypnos.gif                10

   Hypnos-Part.txt           11

   Hypnos-Linux-Build.txt    11

   Text-Pos.txt              12

   Inter-Dev.com             12

   Inter-Port.txt            12

   Test-Suit.txt             13

   Test-Match.bmp            14

   Test-New.txt              15

 

Compare the color high-lighting of the first line of Input with that of Find.

Find:

^a^d^m^a^d^m*.^a^b^d

First line:

Box05-Ses25-Get-Bld-92903.txt  10

            +-----------+

                  *

Notice how * stands for Get-Bld-92903, 3rd <^a> for txt and 3rd <^d> for 10. In Replace we accessed 3rd <^a> by <^a3>, and 3rd <^d> by <^d3>. That is to say, type-cards can be accessed by their ordinals, just like the wild-cards.

As an exercise, now consider the following macro:

Find:

^a^d^m^a^d^m*.^a*^d

Replace:

*.<^a3><a=30?.><^a1> <^d1><a=45?.><^a2> <^d2><a=60?.><^d3>

which gives the following output:

Output

Get-Bld-92903.txt............Box 05.........Ses 25.........10

Importedtest.jpg.............Box 05.........Ses 26.........10

Hypnos.gif...................Box 05.........Ses 27.........10

Hypnos-Part.txt..............Box 05.........Ses 28.........11

Hypnos-Linux-Build.txt.......Box 05.........Ses 29.........11

Text-Pos.txt.................Box 06.........Ses 30.........12

Inter-Dev.com................Box 07.........Ses 31.........12

Inter-Port.txt...............Box 07.........Ses 32.........12

Test-Suit.txt................Box 07.........Ses 33.........13

Test-Match.bmp...............Box 07.........Ses 34.........14

Test-New.txt.................Box 07.........Ses 35.........15

It is apparent that various type-cards are used in Replace to generate various columns above. What might not be so obvious is the use of qualifier <a=m>. There are four types of qualifiers. We will discuss them here.

 

Comments: (a) User can configure (define) his own set of type-cards by using Wild-Card Manager which is found under Work-Pad and Find-Replace library.

(b) Unlike wild-card, rules behind type-cards are simple. However, there is one note-worthy similarity -- the concept of arguments to re-arrange wild-cards holds for type-cards.

(c) Type-cards are available only in Find-and-replace scheme.

 

Knobs         Top

(1) Per-line search:         Top

Recall, wild-card search continues parsing arbitrary text until it matches non-wild text. This search continues even if a line-break is encountered on the way. There comes time when a wild-card search spilling over a line-break becomes undesirable. Consider the following input:

Input

   1. m_tech_cvt_batch_01.gif

   2. m_tech_sch_batch_01.gif

   3. m_tech_cvt_batch_02.htm

   4. m_tech_sch_batch_02.gif

   5. m_tech_cvt_qhelp_01.gif

   6. m_tech_sch_qhelp_01.gif

   7. m_tech_cvt_qhelp_03.htm

   8. m_tech_sch_qhelp_04.gif

<