Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Fix/ticket/832/1 #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bluehazzard
Copy link
Contributor

Add detection and right usage of line endings and indentation to wxSmith

As mentioned in chat, here is a pull request for better commenting and discussing

…rs. Add also script binding for this functions
…er in wxSmith code. (fix #832, thanks Miguel Gimenez)
… correct line endings, so the code can replace them accordingly
* so you have to detect the line ending of the file you are editing.
* If the value is false use cbGetEOLStr(-1) go get the line ending.
*/
extern DLLIMPORT bool cbEnsureLineEndingConsistency();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are wrong. There return a config value. Naming them like this implies they do some action. Name them as getters. And either all of them should have cb prefix or non of them. I think we should start prefixing them.

}


bool wxsCoder::ApplyChangesEditor(cbEditor* Editor,const wxString& Header,const wxString& End,wxString& Code,bool CodeHasHeader,bool CodeHasEnd)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is also wrong. It should be something like ApplyChangesToEditor

bool wxsCoder::ApplyChangesEditor(cbEditor* Editor,const wxString& Header,const wxString& End,wxString& Code,bool CodeHasHeader,bool CodeHasEnd)
{
cbStyledTextCtrl* Ctrl = Editor->GetControl();
int FullLength = Ctrl->GetLength();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

int FullLength = Ctrl->GetLength();
const size_t length = line.length();
// Fetching indentation
if(cbDetectTabStrAutomatically() && !line.IsEmpty() )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please spend some time to be consistent with formatting. Your formatting is always random.
Stick to something like this:

if (condition) // space before the bracket and no spaces around the condition.
{
    <somehting>
}

int FullLength = Ctrl->GetLength();
const size_t length = line.length();
// Fetching indentation
if(cbDetectTabStrAutomatically() && !line.IsEmpty() )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you calling IsEmpty here? You already have the length. Also it is preferable to use the stl versions.

wxChar ch = line.GetChar(IndentPos);
if ( (ch == _T('\n')) || (ch == _T('\r')) ) break;
}
while ( ++IndentPos < length )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected to start with IndentPos=0? I don't understand this loop. What does it do?

{
// Detecting EOL style in source
for ( int i=0; i<FullLength; i++ )
for ( int i=0; i<length; i++ )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you iterating the whole line to detect what is the EOL?

@@ -366,6 +397,10 @@ bool wxsCoder::ApplyChangesEditor(cbEditor* Editor,const wxString& Header,const
return false;
}

wxString EOL;
wxString tab;
GetLineEndingIndentation(Ctrl->GetLine(Ctrl->LineFromPosition(Position)) , tab, EOL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have to copy the line to a string? Can't you work using the wxScintilla API to do the same thing?

@@ -393,8 +427,7 @@ bool wxsCoder::ApplyChangesEditor(cbEditor* Editor,const wxString& Header,const
BaseIndentation.Append(
( ch == _T('\t') ) ? _T('\t') : _T(' '));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated, but here it uses a signed type, so it is actually correct, whatever it does. It is not clear.

wxString EOL;
wxString tab;
int start = BaseContent.rfind('\n', Position);
GetLineEndingIndentation(BaseContent.substr(start < 0 ? 0 : start) , tab, EOL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment what is this doing. Why do you need the substr? Why aren't you comparing with wxString::npos?

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

Successfully merging this pull request may close these issues.

2 participants