Comments (4)
There is "if Right>0 then" on line 718.
from fibplus.
@19Rustam80 There is "if Right>0 then" on line 718.
Yes, but Right is decremented in the loop line 721 and could fall below 0....
from fibplus.
Tested an had this result:
No spaces
'AAAA' -> Left : 1; Right: 4
'AAA' -> Left : 1; Right: 3
'AA' -> Left : 1; Right: 2
'A' -> Left : 1; Right: 1
2 spaces
' BBBB ' -> Left : 3; Right: 6
' BBB ' -> Left : 3; Right: 5
' BB ' -> Left : 3; Right: 4
' B ' -> Left : 3; Right: 3
1 space
' CCCC ' -> Left : 2; Right: 5
' CCC ' -> Left : 2; Right: 4
' CC ' -> Left : 2; Right: 3
' C ' -> Left : 2; Right: 2
Space right
'DDDD ' -> Left : 1; Right: 4
'DDD ' -> Left : 1; Right: 3
'DD ' -> Left : 1; Right: 2
'D ' -> Left : 1; Right: 1
Space left
' EEEE' -> Left : 2; Right: 5
' EEE' -> Left : 2; Right: 4
' EE' -> Left : 2; Right: 3
' E' -> Left : 2; Right: 2
Just space
' ' -> Left : 1; Right: 0
' ' -> Left : 1; Right: 0
' ' -> Left : 1; Right: 0
' ' -> Left : 1; Right: 0
'' -> Left : 0; Right: 0
Used this code:
procedure TFMMain.Button1Click(Sender: TObject);
procedure TrimPositions(const Str:string; var Left,Right:integer);
begin
Right:=Length(Str);
if Right>0 then
begin
Left :=1;
while (Right > 0) and (Str[Right] <= ' ') do Dec(Right);
while (Left <= Right) and (Str[Left] <= ' ') do Inc(Left);
end
else
Left:=0;
end;
var
s : string;
Left,Right : integer;
begin
inherited;
// MDebug is a TMemo
MDebug.Lines.Clear;
MDebug.Lines.Add('No spaces');
s := 'AAAA';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'AAA';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'AA';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'A';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
MDebug.Lines.Add('2 spaces');
s := ' BBBB ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' BBB ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' BB ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' B ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
MDebug.Lines.Add('1 space');
s := ' CCCC ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' CCC ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' CC ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' C ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
MDebug.Lines.Add('Space right');
s := 'DDDD ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'DDD ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'DD ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := 'D ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
MDebug.Lines.Add('Space left');
s := ' EEEE';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' EEE';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' EE';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' E';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
MDebug.Lines.Add('Just space');
s := ' ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := ' ';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
s := '';
TrimPositions(s, Left, Right);
MDebug.Lines.Add(format('''%s'' -> Left : %d; Right: %d', [s, Left, Right]));
end;
from fibplus.
@shavluk , thanks, applied the patch
from fibplus.
Related Issues (20)
- How to activate compression? HOT 1
- Component tpFibClientDataset
- Support for new Firebird 4 data types
- validation HOT 5
- TpFIBDataSet.RefreshFromQuery подставляет лишние записи в датасет
- Access violation in TFIBCustomDataSet.DataEvent on 64bit application with Delphi 11.1 HOT 2
- About version
- Installation
- Incomplete
- FIB Editor not displaying correctly HOT 2
- В дизайтайм-пакете FIBPlusEditors2007.dpk (и т.п.) ссылка на отсутствующий UnitSyntaxMemo.
- TpFIBClientBCDField.GetAsVariant in case IsNull is true
- Can't install FIBPlusEditors2007.dproj
- Can't find by name lookup field with type TFIBWideStringField HOT 1
- cacheSchema slows down user experience when firebird is over internet
- Problem with fibplus installation
- OnValidate event failed.
- Bookmark HOT 3
- SQL Editor Cursor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fibplus.