|
|
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » Enhancing project templates (upt files)
Enhancing project templates (upt files) [message #5407] |
Tue, 19 September 2006 16:57  |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
It seems to be a well-established standard to write CAPITALIZED include guards. But this is not possible when using project templates.
As I'm writing my own project templates anyway, I decided to patch Template.cpp to enable uppercase include guards (which might be selected by a corresponding option).
The patch requires just a minor change of a single function:
Original function
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
ArrayMap<String, EscValue> var;
String n = ~package;
int q = n.ReverseFind('/');
var.Add("PACKAGE", q >= 0 ? n.Mid(q + 1) : n);
return var;
}
Patched function
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
ArrayMap<String, EscValue> var;
String n = ~package;
int q = n.ReverseFind('/');
n = q >= 0 ? n.Mid(q + 1) : n;
var.Add("PACKAGE", n);
var.Add("PACKAGE_UPPERCASE", ToUpper(n));
return var;
}
Might I suggest to consider the adoption of this patch into the official Ultimate++ release?
If so, please let me know as soon as possible, as I'm writing a project template documentation.
Werner
|
|
|
|
|
|
|
|
|
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5480 is a reply to message #5415] |
Tue, 26 September 2006 12:17   |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
Thank you for adopting my suggestion.
After using "PACKAGE_UPPERCASE" for a couple of days, I'm no longer happy with the simplistic creation of its content. This was obviously an over-quick suggestion. Sorry!
As far as I can see, it is quite common - and I adhere to this quasi-standard - to capitalize mixed-uppercase-lowercase identifiers by inserting an underscore ("_") when the change from a lowercase letter to an uppercase letter indicates a new component.
That is why I wrote the following tiny function, which I suggest to include into Ultimate++, maybe into "uppsrc/ide".
I intentionally wrote it as a non-menber function of "String" (compare e. g., Stroustrup, The C++ Programming Language, Special Edition, 10.3.2; Sutter, Alexandrescu, C++ Coding Standards, 44; Meyers, Effective C++, 4.6 / 23).
String MkInclGuard(const String& name)
{
String output("");
int str_len = name.GetLength();
for (int i = 0; i < str_len; ++i)
{
int ch = name[i];
if (IsAlNum(ch))
{
output += ToUpper(ch);
if (i < str_len - 1)
if (IsLower(ch) && IsUpper(name[i + 1]))
output += '_';
}
else
output += '_';
}
return output;
}
The patched function then reads:
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
ArrayMap<String, EscValue> var;
String n = ~package;
int q = n.ReverseFind('/');
n = q >= 0 ? n.Mid(q + 1) : n;
var.Add("PACKAGE", n);
var.Add("PACKAGE_UPPERCASE", MkInclGuard(n));
return var;
}
Werner
[Updated on: Tue, 26 September 2006 12:24] Report message to a moderator
|
|
|
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5481 is a reply to message #5480] |
Tue, 26 September 2006 12:26   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Werner wrote on Tue, 26 September 2006 06:17 | Thank you for adopting my suggestion.
After using "PACKAGE_UPPERCASE" for a couple of days, I'm no longer happy with the simplistic creation of its content. This was obviously an over-quick suggestion. Sorry!
As far as I can see, it is quite common - and I adhere to this quasi-standard - to capitalize mixed-uppercase-lowercase identifiers by inserting an underscore ("_") when the change from a lowercase letter to an uppercase letter indicates a new component.
That is why I wrote the following tiny function, which I suggest to include into Ultimate++, maybe into "uppsrc/ide".
I intentionally wrote it as a non-menber function of "String" (compare e. g., Stroustrup, The C++ Programming Language, Special Edition, 10.3.2; Sutter, Alexandrescu, C++ Coding Standards, 44; Meyers, Effective C++, 4.6 / 23).
String MkInclGuard(const String& name)
{
String output("");
int str_len = name.GetLength();
for (int i = 0; i < str_len; ++i)
{
int ch = name[i];
if (IsAlNum(ch))
{
output += ToUpper(ch);
if (i < str_len - 1)
if (IsLower(ch) && IsUpper(name[i + 1]))
output += '_';
}
else
output += '_';
}
return output;
}
The patched function then reads:
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
ArrayMap<String, EscValue> var;
String n = ~package;
int q = n.ReverseFind('/');
n = q >= 0 ? n.Mid(q + 1) : n;
var.Add("PACKAGE", n);
var.Add("PACKAGE_UPPERCASE", MkInclGuard(n));
return var;
}
Werner
|
I think we should add it to the Core, it is a nice complement to "InitCaps" sort of function.
I only do not quite like the name (because it is not necessarily related to include guards) - what about something like "ToLowerUnderscoreCaps"? 
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 16:43:44 CEST 2025
Total time taken to generate the page: 0.01191 seconds
|
|
|