Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the cfg to allow strings with \n or \r? #7

Open
ScottEAdams opened this issue Apr 6, 2013 · 8 comments
Open

How to set the cfg to allow strings with \n or \r? #7

ScottEAdams opened this issue Apr 6, 2013 · 8 comments

Comments

@ScottEAdams
Copy link

For example:

[NSString stringWithFormat:@"%@\r\n", message]

When running the formatter it also removes these instances of new lines / carriage return.

@nathanielcook
Copy link

I ran into this same problem. The problem is not with the config. It's with the AppleScript that is run. On my system the AppleScript is at ~/Library/Services/Uncrustify_opened_Xcode_sources.workflow

The problematic code is here:

if (suffix = "m" or suffix = "h") then
    set rawSource to quoted form of (text of currentDocument as Unicode text)
    set formattedSource to do shell script " echo " & rawSource & " | /usr/local/bin/uncrustify -l OC -q -c " & "'" & uncrustifyConfigFilePath & "'"
    set text of currentDocument to formattedSource
end if

I have not yet figured out a way to fix it though, not have I found a workaround.

@nathanielcook
Copy link

This code "fixes" the problem, but it creates a new one:

if (suffix = "m" or suffix = "h") then
    set rawSource to quoted form of (text of currentDocument as Unicode text)
    set formattedSource to do shell script " echo " & rawSource & " | /usr/local/bin/uncrustify -l OC -q -c " & "'" & uncrustifyConfigFilePath & "'"

    set AppleScript's text item delimiters to the return
    set the item_list to every text item of formattedSource
    set AppleScript's text item delimiters to the "\\n"
    set formattedSource to the item_list as string
    set AppleScript's text item delimiters to ""

    set text of currentDocument to formattedSource
end if

The problem is that removes ALL line breaks--not just the ones within a string. What we need is a regex, which is above my head. I'm hoping some else can find a fix for this.

@nathanielcook
Copy link

Here's a link to a stackoverflow post that I created before finding out that it was a bug. I'm posting this as a cross reference just in case anyone there finds a workaround.

http://stackoverflow.com/questions/16993420/uncrustify-turning-newline-characters-that-are-part-of-a-string-into-actual-new

@nathanielcook
Copy link

I just posted a workaround on the stackoverflow page. Here it is:

NSInteger newLineAsciiCode = 10;
NSString *newLineCharacter = [NSString stringWithFormat:@"%c", newLineAsciiCode];
NSString *someString = [NSString stringWithFormat:@"Lorem ipsum dolor.%@Eget nisl nec risus", newLineCharacter];

@rardoz
Copy link

rardoz commented Aug 4, 2013

This string thing is such a bitch.

@rardoz
Copy link

rardoz commented Aug 4, 2013

Solved it. Given the direction above, replace the statement with whats below this paragraph. I submitted a commit, hopefully it can get fixed up and nobody else has to waste their Sunday wresting with AppleScript. 👍

if (suffix = "m" or suffix = "h") then

tell application "Xcode" to (do shell script "'/usr/local/bin/uncrustify' -c " & "'" & uncrustifyConfigFilePath & "' -l OC --no-backup '" & currentDocumentPath & "'")

end if
end repeat
display dialog "DONE"
end tell

Thanks for the plugin by the way!
-Robert

@rardoz
Copy link

rardoz commented Aug 4, 2013

This might be ovi, but the &'s are actually & 's.

@nathanielcook
Copy link

Thanks for updating this heliumroe. I have tested your fix briefly and it seems to well for me. I have marked your answer as the accepted answer on stackoverflow. Once your pull request gets merged I would think that this issue could be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants