Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » Enhancing project templates (upt files)
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5481 is a reply to message #5480] Tue, 26 September 2006 12:26 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13976
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"? Smile
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Assamblies and nests
Next Topic: Ctrl Documentation Bug?
Goto Forum:
  


Current Time: Thu May 09 15:06:23 CEST 2024

Total time taken to generate the page: 0.02021 seconds