davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.
GNU General Public License v3.0
483 stars 77 forks source link

The space will be generated on both sides of the "\" or "/" in strings. #109

Open DWin233 opened 3 years ago

DWin233 commented 3 years ago

Hello, I found a problem or bug when i use your tool to format my code. The space will be automatically generated on both sides of the "\" or "/" in strings. QQ截图20210608100827 image

davidvarga commented 3 years ago

Hi, I cannot reproduce the issue. I am trying with Matlab R2020b, executing MBeautify.formatCurrentEditorPage() on the following content using defautl configuration:

self.resultDir = self.totalDir + path + "/";
self.resultDir = self.totalDir + path + "\";
self.totalDir = ".\results\";

The result is the same as the input in my case.

Is there any special context I am missing for my tests?

DWin233 commented 3 years ago

My code is edited with Matlab 2020a. Here is the test code:

self=struct();  
path="1";  
self.totaldir=".\results\";
self.resdir=self.totaldir+path+"\";

After executing MBeautify.formatCurrentEditorPage() using default configuration, this code changes to :

self = struct();  
path = "1";  
self.totaldir = " .\ results \ ";  
self.resdir = self.totaldir + path + " \ ";  

I don't know whether this difference is due to the different versions of Matlab we use.

davidvarga commented 2 years ago

Hi @DWin233 ,

I tried again, this time with R2020b, still no "luck" reporducing it.

Are you using the default configuration or a moified one?

lvdgraaff commented 11 months ago

Hi David,

Thanks a lot for creating MBeautifier. Its a great tool and I'm using it a lot. Today I bumped into the same behavior as described in this issue. In my case I format:

path = "\\host\folder\file";

which results in

path = " \  \ host \ folder \ file";

I use the MBeautify.formatCurrentEditorPage() function for formatting. I use v1.3.2. Platform: Windows 10. Matlab version R2023a. As far as I'm aware I use a default configuration but if there are any settings that might impact this behavior, let me know.

I would really appreciate if you would take another look at this issue and I'm happy to provide you with any further information.

Best, Leon

lvdgraaff commented 11 months ago

Just some debugging:

Using chars:
path = '\\host\folder\file';                ->    path = '\\host\folder\file';                (Correct)

Using string:
path = "//host/folder/file";               ->    path = " /  / host / folder / file";      (Incorrect)

Using other operators in a string:
text = "a+b"                                      ->    text = "a + b"                                   (Incorrect)

In comments
% //host/folder/file                           ->    % //host/folder/file                          (Correct)

In text arguments
disp //host/folder/file                        ->   disp //host/folder/file                       (Correct)

So it appears this problem relates to the string environment not being recognized as such. Note the latter example contradicts #122.