davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

DWin233 opened this issue · comments

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

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?

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.

Hi @DWin233 ,

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

Are you using the default configuration or a moified one?

commented

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

commented

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.

  • formatFile has the same issue as formatCurrentEditorPage