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
 Feature Requests
 const std::string& foo to const std::string &foo
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vertexwahn
Senior Member

35 Posts

Posted - Jul 01 2015 :  05:26:17 AM  Show Profile  Reply with Quote
Would be nice if there would be an easy way to change function parameters from


const std::string& foo


to


const std::string &foo


For instance:

virtual void setValue(
	const BlueFramework::Core::String& name,
	const BlueFramework::Core::Math::vector2i& value) = 0;


to


virtual void setValue(
	const BlueFramework::Core::String &name,
	const BlueFramework::Core::Math::vector2i &value) = 0;


I have hundreds of lines of code where the reference & is bound to the type and not to the name - Would be very nice this refactoring can be done automatically

The following options would be nice:

  • Bind reference symbol (&) to variable name

  • Bind reference symbol (&) to variable type

  • Bind pointer symbol (*) to variable name

  • Bind pointer symbol (*) to variable type


Dusan
Whole Tomato Software

Slovakia
177 Posts

Posted - Jul 02 2015 :  12:51:28 PM  Show Profile  Reply with Quote
You can use built-in Find and Replace tool with the following regular expression to achieve what you need:

In VS2010 and older:

Pattern to search for:
{[(,]:b*<:i>}{:b*}{[&*]}{:b*}{<:i>}

Replacement:
\\1\\2\\4\\3\\5

From VS2012:

Pattern to search for:
([,(]\\s*\\b(?:_\\w+|[\\w-[0-9_]]\\w*)\\b)(\\s*)([&*])(\\s*)(\\b(?:_\\w+|[\\w-[0-9_]]\\w*)\\b)

Replacement:
$1$2$4$3$5

Did this help?

Edited by - Dusan on Jul 05 2015 04:19:46 AM
Go to Top of Page

Vertexwahn
Senior Member

35 Posts

Posted - Jul 07 2015 :  07:13:26 AM  Show Profile  Reply with Quote
There are some corner cases where this does not work properly:

Case 1 (multiplication):

- struct pos *points = (struct pos *) glMapBufferRange( GL_SHADER_STORAGE_BUFFER, 0, NUM_PARTICLES * sizeof(struct pos), bufMask );
+ struct pos *points = (struct pos *) glMapBufferRange( GL_SHADER_STORAGE_BUFFER, 0, NUM_PARTICLES  *sizeof(struct pos), bufMask );


Case 2 (bitwise AND):

- if  (nFeatureInfo & nIds)
+ if  (nFeatureInfo  &nIds)


Case 3 (finds only one occurrence)

-  friend std::istream& operator>>(std::istream& is, icmp_header& header)
+  friend std::istream& operator>>(std::istream& is, icmp_header &header)


Case 4 (comments):

 	/** Construction from existing values for mantissa, sign
-	 *  and exponent. No validation is performed.
+	   *and exponent. No validation is performed.
 	 *  @note The exponent is unsigned and biased by #BIAS 
 	 */

Edited by - Vertexwahn on Jul 07 2015 07:15:22 AM
Go to Top of Page

Dusan
Whole Tomato Software

Slovakia
177 Posts

Posted - Jul 08 2015 :  12:08:54 PM  Show Profile  Reply with Quote
I agree that it is not ideal solution, but you can accept or move next during replacement.

If you need to reformat too many of lines, then I would recommend you to use some extension for Visual Studio such as AStyle or clang-format.

Usually we don't focus on cases which already have free or opensource solutions available (like reformatting), so even if I would create a case for such tool, it would probably not get high priority.
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