Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Upper & Lower
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 11 2012 :  11:13:06 AM  Show Profile  Reply with Quote
Hi

I love the idea of Text altering suffixes .

Like many C# developers I use the case sensitivity to do things like ...

CustomerType customerType = new CustomerType()

What about _Camel and _ Pascal as well

$VariableType$ $VariableType_Camel$ = new $VariableType$();

Wow what a labour saver

Mike

feline
Whole Tomato Software

United Kingdom
19191 Posts

Posted - Apr 12 2012 :  12:28:59 PM  Show Profile  Reply with Quote
This makes sense, I have put in a feature request to see what our developers make of this:

case=66101

Thinking about this, since VA cannot automatically work out where the word boundaries lay, all we can do here is to upper or lower case the first letter in the entered text, leaving you to Upper case any letters in the middle that need it. Or do you have some thoughts on how we could spot word boundaries?

zen is the art of being at one with the two'ness
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 13 2012 :  12:51:34 AM  Show Profile  Reply with Quote
Hi

For code generation , these transformations are quite common , CodeSmith has a whole String Utility that does this including

ProperCase
ToCamel
ToPascal
Singular
Plural

etc.
Proper case is where all not alpha charchters are removed say "_" so you do that first so Customer_Type becomes CustomerType before you start

Its quite simple , for Camel Case if the word is Proper Case eg CustomerType , you simply strip off the first character and make it .ToLower().

For Pascal case strip off the first Char and make it to Upper

Singular & Plural take a bit more effort as some words don't obey the "rules" singular = knock an s etc What is the Plural of Equipment for example ?

The quirks of the English Language.


something like this...


public string ProperCase(string originalName)
{
string newName = originalName.Substring(0,0).ToLower();
string character = string.Empty;

for (int i = 1; i < originalName.Length; i++)
{
character = originalName.Substring(i,1);

if (character !="_") // or any other non alpha as desired
{
newName = newName += character;
}

}
return newName;
}

public string CamelCase(string originalName)
{
string newName = string.Empty;
newName = ProperCase(originalName);
return newName.Substring(0, 1).ToLower() + newName.Substring(1, newName.Length - 1);

}

public string PascalCase(string originalName)
{
string newName = string.Empty;
newName = ProperCase(originalName);
return newName.Substring(0, 1).ToUpper() + newName.Substring(1, newName.Length - 1);

}

hope this helps

Mike
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 13 2012 :  01:02:08 AM  Show Profile  Reply with Quote
Try the right Proper case

public string ProperCase(string originalName)
{
string newName = originalName.Substring(0,1).ToUpper();
string character = string.Empty;
bool caps = false;

for (int i = 1; i < originalName.Length ; i++)
{
character = originalName.Substring(i,1);

if (character !="_") // or any other non alpha as desired
{
if (caps)
{
newName = newName += character.ToUpper();
}
else
{
newName = newName += character.ToLower();
}
caps = false;
}
else
{
// next Char should be Caps
caps = true;
}

}
return newName;
}
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19191 Posts

Posted - Apr 13 2012 :  11:28:57 AM  Show Profile  Reply with Quote
How do you see this being used, how do you see this working?

This thread seems to be based on the new VA Snippet suffixes, _Lower and _Upper. But these are only available when you are using a user variable in a VA Snippet, so when your VA Snippet prompts you for the string to place into the Snippet.

So we are not transforming any existing string in the editor, we are only transforming a specific string you have typed into the VA Snippet prompt dialog, ready to insert into your code. Given this restriction, why would you type "customer_type " only to want to ask the snippet to convert this into "CustomerType"?

Typing in "CustomerType" and having this converted into both "CustomerType" and "customerType", to be used at two different points in the same line makes a lot of sense, and was how I read your original post. Now I am wondering if you are thinking of something different to this, and to what I understood.

zen is the art of being at one with the two'ness
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 14 2012 :  04:41:36 AM  Show Profile  Reply with Quote
Sorry maybe I'm not clear

If I want

CustomerType customerType = new CustomerType();

Currently I create a snippet

$VarType$ $CamelVarType$ = new $VarType$();

So when I use the snippet I am prompted for 2 entries , one Pascal , One Camel , which I have to do manually

What I am suggesting is

$VarType$ $VarType_Camel$ = new $VarType$();

So that I am prompted for ONE entry $VarType$ not 2 , the transformation to %VarType_Camel$ is done on expansion of the snippet as yu are doing with your upper lower functions. Its just a bit more complicated.

Its so common to use the pascal/camel split for type and variable in C# I thought it would be a nice add on.

I hope this clarifies

Mike
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19191 Posts

Posted - Apr 16 2012 :  12:34:39 PM  Show Profile  Reply with Quote
This is the feature request I have put in, but the current feature is very simple. The "_Camel" and "_Pascal" commands will simply change the case of the first letter, and do nothing else.

For a string "foobar" or "getxmldatatypeinfo" how should "_Camel" and "_Pascal" work? It is easy to say to a person "make the first character of each word upper case", but how do we define "word" to VA?

Compare the block of characters to all words in all installed dictionaries? That is not going to work well, simply because many words contain words, so VA is not going to be able to work out, reliably, where the word boundaries lay.

If these commands assume you type "foo_bar" into the VA Snippet prompt dialog, why not just type "fooBar" instead? Why handle underscore, and turn the next letter into an upper case letter inside the VA Snippet, when it is just as easy to upper case the letters as you type them?

I assume I am overlooking something obvious here, I just have not worked out what yet

zen is the art of being at one with the two'ness
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 17 2012 :  02:21:29 AM  Show Profile  Reply with Quote
That would work OK

For Pascal and Camel , first char is right , if the word boundaries are capitalised then they stay that way .

Proper case is more important in code generation eg when you have Table names with Underscores eg QA_TESTS_LOT where you would like derived Classes on code genration to look "Nice" ie QaTestsLot.

Mike
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19191 Posts

Posted - Apr 17 2012 :  3:53:38 PM  Show Profile  Reply with Quote
*ah* so you would like to apply these modifiers to other VA Snippet tokens, e.g. $BaseClassName$ ?

This makes more sense, but $BaseClassName$ only works if there already is a base class, so you cannot use this to create a new, derived class directly.

I am just trying to be clear on the usage here, to make a good case in the feature request.

zen is the art of being at one with the two'ness
Go to Top of Page

Mike ONeill
Tomato Guru

South Africa
103 Posts

Posted - Apr 23 2012 :  06:27:57 AM  Show Profile  Reply with Quote
Hi

No not specifically using a $BaseClass$ or pre set variables in VAX , just simply as a Text entry based on a simple variable in the snippett

Eg.

If I enter Text = "Customer" , I would like to use the word in a snippett in either its Camel Case version or Pascal version

eg $VarName_ToPascal$ $VarName_ToCamel$ = new $VarName_ToPascal$();

to Give

Customer customer = new Customer();

Currently I would have to define 2 variables and enter one pascal and one camel


and similarly if I want to use Camel Case prefixes to other constructs such as

$VarName_ToCamel$BindingSource to give customerBindingSource

I hope I am making sense ??

Mike
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19191 Posts

Posted - Apr 23 2012 :  1:54:04 PM  Show Profile  Reply with Quote
Yes, this makes sense, and this is what case=66101 covers, modifying the first letter of user entered text.

One of our developers has actually had a look at this, and it should be present in the next build of VA, so you should be able to start using this in a few weeks time. I do like this idea, simple yet very useful

zen is the art of being at one with the two'ness
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Feb 01 2013 :  10:43:18 PM  Show Profile  Reply with Quote
This was implemented to a certain degree in build 1905.

Append "_Pascal" to make the first character of the input be upper-case.
Append "_Camel" to make the first character of the input be lower-case.

The _Pascal and _Camel suffixes are only applicable to user-defined substitutions.
They only affect the first character of the input (they do not operate on sub-words/sub-strings).
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000