Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: The ANSI String Challenge



Permlink Replies: 209 - Last Post: Oct 27, 2014 4:32 AM Last Post By: Bruce McGee
Christopher Burke

Posts: 580
Registered: 9/25/99
The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 2:28 PM
This message is no longer available.
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 3:44 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher,

| 2. THe block is ...

What's "THe block"?

--

Q

1.19.1.372 (Q's Broken Toolbar.)
> Rich <

Posts: 171
Registered: 2/6/09
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 6:08 PM   in response to: Quentin Correll in response to: Quentin Correll
Quentin Correll wrote:

What's "THe block"?

I figure that's the chunk (block) of data that is sent via the packet.

I don't know why Christopher says this: "You have an ansi string of up to 128 bytes". It looks like an array of up to 128 bytes.
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 10:13 PM   in response to: > Rich < in response to: > Rich <
Rich < &lt;&gt; wrote in news:696690 at forums dot embarcadero dot com:

Quentin Correll wrote:

What's "THe block"?

I figure that's the chunk (block) of data that is sent via the packet.

I don't know why Christopher says this: "You have an ansi string of up
to 128 bytes". It looks like an array of up to 128 bytes.

I'm sorry, the specification says ASCII string of up to 128 bytes...but
anyway it is is an array of up to 128 ASCII characters (what I like to call
a string).
> Rich <

Posts: 171
Registered: 2/6/09
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 10:29 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

(what I like to call a string).

You should stop that and call it an array.
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 11:49 PM   in response to: > Rich < in response to: > Rich <
Rich < &lt;&gt; wrote in news:696704 at forums dot embarcadero dot com:

Christopher Burke wrote:

(what I like to call a string).

You should stop that and call it an array.

Changing the name does nothing to make it easier to process.

I could change the name integer to doublebyte ... doesn't really solve
anything.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:19 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rich < &lt;&gt; wrote in news:696704 at forums dot embarcadero dot com:

Christopher Burke wrote:

(what I like to call a string).

You should stop that and call it an array.

Changing the name

You should USE an array for that. So it is a byte array which contains
some ASCII and some binary data.
--
Rudy Velthuis http://www.rvelthuis.de

"Getting an education was a bit like a communicable sexual disease.
It made you unsuitable for a lot of jobs and then you had the urge
to pass it on." -- Terry Pratchett, Hogfather
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:18 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rich < &lt;&gt; wrote in news:696690 at forums dot embarcadero dot com:

Quentin Correll wrote:

What's "THe block"?

I figure that's the chunk (block) of data that is sent via the
packet.

I don't know why Christopher says this: "You have an ansi string of
up to 128 bytes". It looks like an array of up to 128 bytes.

I'm sorry, the specification says ASCII string of up to 128
bytes...

Whose specification is that? Data are most definitely not ASCII, unless
they are B64, UU or similarly encoded.

--
Rudy Velthuis http://www.rvelthuis.de

"The Brush Dance is a Yurok healing ritual where being true to
yourself means give your best to a person in need. Being true
to yourself is the one and only Yurok Indian Law."
-- Brush Dance Journal
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 11:42 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696747
@forums.embarcadero.com:

Christopher Burke wrote:

I'm sorry, the specification says ASCII string of up to 128
bytes...

Whose specification is that? Data are most definitely not ASCII, unless
they are B64, UU or similarly encoded.

To clarify - ASCII consists of characters 0...127, so the incoming block of
up to 128 CHARACTERS is ASCII.

http://en.wikipedia.org/wiki/ASCII

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 11:57 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696747
@forums.embarcadero.com:

Christopher Burke wrote:

I'm sorry, the specification says ASCII string of up to 128
bytes...

Whose specification is that? Data are most definitely not ASCII,
unless they are B64, UU or similarly encoded.

To clarify - ASCII consists of characters 0...127, so the incoming
block of up to 128 CHARACTERS is ASCII.

http://en.wikipedia.org/wiki/ASCII


Then there is no problem at all. You can do all processing in
UnicodeStrings.

--
Rudy Velthuis http://www.rvelthuis.de

"Be tolerant of the human race. Your whole family belongs to it
-- and some of your spouse's family too." -- Anonymous.
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 15, 2014 7:32 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697109
@forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings, I can walk through solid walls.

Godamn it is easy to make claims.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 15, 2014 7:38 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697109
@forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings

Plane or helicoptor.

I can walk through solid walls.

Door

Godamn it is easy to make claims.

You just need the right tools.

But you're claiming that you can't deal with strings, even when
presented with code samples.

I honestly don't understand what's preventing you from seeing this.

--
Regards,
Bruce McGee
Glooscap Software
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:16 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee <bmcgee at glooscap dot com> wrote in news:697379
@forums.embarcadero.com:

Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697109
@forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings

Plane or helicoptor.

Without wings...


I can walk through solid walls.

Door

Solid + Wall

You seem to have problems with specifications.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:14 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697379
@forums.embarcadero.com:

Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in
news:697109 >> @forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings

Plane or helicoptor.

Without wings...

helicopter.

I can walk through solid walls.

Door

Solid + Wall

A wall with a door in it is still a wall. Check the building code.

You seem to have problems with specifications.

I'm not programmer who keeps insisting that a simple coding problem is
impossible, even after having other people do his homework for him.

--
Regards,
Bruce McGee
Glooscap Software
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:39 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
Without wings...

helicopter.

It's not because the wings rotate they cease to be wings.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:54 PM   in response to: Dominique Willems in response to: Dominique Willems
Dominique Willems wrote:

Bruce McGee wrote:
Without wings...

helicopter.

It's not because the wings rotate they cease to be wings.

Moving target specification. My favourite kind.

--
Regards,
Bruce McGee
Glooscap Software
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 5:12 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
Moving target specification. My favourite kind.

Huh? Not reading the thread, just spotted wings. I like wings. Carry on.
Phillip Woon

Posts: 189
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 5:25 PM   in response to: Dominique Willems in response to: Dominique Willems
Dominique Willems wrote:
Bruce McGee wrote:
Without wings...

helicopter.

It's not because the wings rotate they cease to be wings.

Hot air balloon?
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 2:17 AM   in response to: Phillip Woon in response to: Phillip Woon
Phillip Woon wrote:
Hot air balloon?

That's better. You win the Internet.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 9:49 AM   in response to: Dominique Willems in response to: Dominique Willems
Dominique Willems wrote:

Phillip Woon wrote:
Hot air balloon?

That's better. You win the Internet.

He can't. I already have it. <g>

--
Rudy Velthuis http://www.rvelthuis.de

"Distrust any enterprise that requires new clothes."
-- Henry David Thoreau (1817-1862)
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 9:56 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:
That's better. You win the Internet.

He can't. I already have it. <g>

You can have all the YouTube comments.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 3:11 PM   in response to: Dominique Willems in response to: Dominique Willems
Dominique Willems wrote:

Rudy Velthuis (TeamB) wrote:
That's better. You win the Internet.

He can't. I already have it. <g>

You can have all the YouTube comments.

Since I have the Internet, I have those too.

--
Rudy Velthuis http://www.rvelthuis.de

"If FORTRAN has been called an infantile disorder, then PL/I must
be classified as a fatal disease." -- Edsger Dijkstra
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 15, 2014 11:42 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697109
@forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings, I can walk through solid walls.

I see you try to be sarcastic. Keep trying.

it is easy to make claims.

It is easy enough to verify that claim with code as well. Did you see
the small modifications of the sample code you posted (which would not
compile and which did not work, BTW) and which does not need
AnsiStrings, SINCE IT DOES ALL PROCESSING IN UNICODESTRINGS?

Most of the mods were required to get your logic right. Only one mod
was required to convert ASCII to Unicode.

--
Rudy Velthuis http://www.rvelthuis.de

"If you were plowing a field, which would you rather use? Two
strong oxen or 1024 chickens?"
-- Seymour Cray (1925-1996), father of supercomputing
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:17 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697418
@forums.embarcadero.com:

Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697109
@forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings, I can walk through solid walls.

I see you try to be sarcastic. Keep trying.

I try to be reasonable, but it seems that doesn't work with you guys.


It is easy enough to verify that claim with code as well.

I can verify that to get my stuff into unicode, I require ansi strings.
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 5:31 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

I try to be reasonable, but it seems that doesn't work with you guys.
I can verify that to get my stuff into unicode, I require ansi strings.

Why do you keep on claiming you would need AnsiStrings for the pesented task?
You were presented several solutions based on data in TBytes and the payload
converted from those bytes to UnicodeString in various ways, none that required
presence of AnsiString or AnsiChar or PAnsiChar.

--
Tom Brunberg
firstname.lastname@welho.com
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 10:44 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg <nospam@to.me> wrote in news:697490 at forums dot embarcadero dot com:

Christopher Burke wrote:

I try to be reasonable, but it seems that doesn't work with you guys.
I can verify that to get my stuff into unicode, I require ansi
strings.

Why do you keep on claiming you would need AnsiStrings for the
pesented task?

Mainly because I do... seems like a good enough reason to me.

Only ONE person even tried to solve the problem presented, the rest just
bantered continuously saying but not doing.

That one solution created was a specific non-reusuable state machine that
still emulated ansi-string functionality to do the trick.
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 11:16 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697571 at forums dot embarcadero dot com...

Only ONE person

FALSE.

even tried to solve the problem presented, the rest just
bantered continuously saying but not doing.

That one solution created was a specific non-reusuable state machine that
still emulated ansi-string functionality to do the trick.

You need to review the thread more carefully.

You've apparently missed some of the posts.
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:11 AM   in response to: david hoke in response to: david hoke
david hoke <dhoke.nojunk@east-shore.com> wrote in
news:697586 at forums dot embarcadero dot com:

You need to review the thread more carefully.

You've apparently missed some of the posts.

Nah - I've given up on the thread, just people blowing pointless hot air in
my face now.

The turned the thread into a defacto of the other one.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:17 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

david hoke <dhoke.nojunk@east-shore.com> wrote in
news:697586 at forums dot embarcadero dot com:

You need to review the thread more carefully.

You've apparently missed some of the posts.

Nah - I've given up on the thread, just people blowing pointless hot
air in my face now.

No, you haven't, you are still posting here, while ignoring people who
took up the challenge. And you are simply stating wrong facts. Doesn't
make you look good at all.

--
Rudy Velthuis http://www.rvelthuis.de

"Everything has been figured out, except how to live."
-- Jean Paul Sartre

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 12:59 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher wrote:

Mainly because I do... seems like a good enough reason to me.

But you still have not presented **WHY** you require AnsiString so badly.
The RTL certainly does not require it, so it has to be due to a limitation
inyour own code that you are refusing to acknowledge and/or change.

Only ONE person even tried to solve the problem presented, the
rest just bantered continuously saying but not doing.

Excuse me? You were given *multiple** solutions by **multiple** people showing
how to solve the problem.

--
Remy Lebeau (TeamB)
Nick Hodges

Posts: 2,414
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 1:07 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Excuse me? You were given multiple solutions by multiple people
showing how to solve the problem.

And somehow he rejects these by saying "You're just recreating what
AnsiStrings do."

Uhm, yeah, exactly.

--
Nick
Delphi Programming is Fun
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 1:48 PM   in response to: Nick Hodges in response to: Nick Hodges
Nick Hodges wrote:
Remy Lebeau (TeamB) wrote:

Excuse me? You were given multiple solutions by multiple people
showing how to solve the problem.

And somehow he rejects these by saying "You're just recreating what
AnsiStrings do."

Now, do it without rewriting the code...

Uhm, yeah, exactly.

Exactly.

Dan
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 4:25 PM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to make
changes to your code. We've been warned about it since the Borland days.

In this case, a trivial chage will do the trick.

--
Regards,
Bruce McGee
Glooscap Software
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:14 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to make
changes to your code. We've been warned about it since the Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:43 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:
OK - the incoming data IS NOT BINARY DATA.

Of course it's binary data: it's all just zeroes and ones. Those bits are then interpreted a certain way, as specified by the protocol. You've been shown how to interpret those bits in a way which does not require the AnsiString type.

The fundamental difference between using TBytes and AnsiString for arrays of of characters (ie strings) is how the encoding is stored and how the character data is converted to a different encoding:
- AnsiString has the character encoding stored along with the character array, and this is used implicitly during conversions.
- TBytes is character encoding oblivious, and the data has to be explicitly converted using an explicitly provided encoding by the programmer.

- Asbjørn
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 3:23 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.

Combined with binary data.

In a string.

Which you were warned against doing because the size of a character
might change.

--
Regards,
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 3:58 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.

Combined with binary data.

In a string.

Which you were warned against doing because the size of a character
might change.

Bruce, what is this nonsence?
Christoffer has several times said it is an ascii string with NO EMBEDDED binary data.
Why are you repeatedly claiming otherwise?

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:19 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
Bruce McGee wrote:

Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.

Combined with binary data.

In a string.

Which you were warned against doing because the size of a character
might change.

Bruce, what is this nonsence?
Christoffer has several times said it is an ascii string with NO EMBEDDED binary data.
Why are you repeatedly claiming otherwise?

Because he repeatedly writes that there are binary characters embedded in the protocol.

It's also in his made up protocol in the first message of this thread.

--
Regards
Bruce McGee
Glooscap Software
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:26 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Christoffer has several times said it is an ascii string with NO
EMBEDDED binary data. Why are you repeatedly claiming otherwise?

Because he repeatedly writes that there are binary characters
embedded in the protocol.

They are control characters, in the range #1..#31. That's OK and also
part of Unicode.
--
Rudy Velthuis http://www.rvelthuis.de

"It is practically imposible to teach good programming to
students that have had a prior exposure to BASIC: as potential
programmers they are mentally mutilated beyond hope of
regeneration." -- Edsger Dijkstra
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:40 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.

Combined with binary data.

In a string.

Which you were warned against doing because the size of a character
might change.

Bruce, what is this nonsence?
Christoffer has several times said it is an ascii string with NO EMBEDDED binary data.
Why are you repeatedly claiming otherwise?

Because he repeatedly writes that there are binary characters embedded in the protocol.

It's also in his made up protocol in the first message of this thread.

I would have expected you to know better. Since you don't, take a look at
http://en.wikipedia.org/wiki/ASCII
Then read through the messages and find the one where he specifically says
that the message consists of only characters in the ascii range, #0..#127.

I don't defend Christoffer for being stubborn or not able to admit being wrong
but it serves nobody to throw up pure noise on the wall. You as an advocate for
less noise should really act as an example.

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 5:03 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
Bruce McGee wrote:

Because he repeatedly writes that there are binary characters embedded in the protocol.

It's also in his made up protocol in the first message of this thread.

I would have expected you to know better. Since you don't, take a look at
http://en.wikipedia.org/wiki/ASCII
Then read through the messages and find the one where he specifically says
that the message consists of only characters in the ascii range, #0..#127.

Anything between #0 and #31 are non printable characters or binary data. Can we agree on that?

You should not be using strings for binary data. Even if you can still shoehorn it into Unicode strings.

I don't defend Christoffer for being stubborn or not able to admit being wrong
but it serves nobody to throw up pure noise on the wall. You as an advocate for
less noise should really act as an example.

I'll admit to adding to the noise, especially in this case, but I can't let this "it's impossible" nonsense stand.

Unsupportable statements like this cloud the issue for people who have a legitimate use for 8-bit strings.

In fact, this guy can't possibly be as dense as he's pretending to be, so it makes me wonder if he's doing it on purpose.

Anyway, I can't promise less noise, but I'll count to ten before adding to it in this thread.

--
Regards
Bruce McGee
Glooscap Software
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 5:42 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Anything between #0 and #31 are non printable characters or binary
data. Can we agree on that?

Actually, no. They are part of ASCII and thus of Unicode. They are no
more "binary data" than 'A' or 'z'. They are valid ASCII and Unicode
control characters. FWIW, Unicode even knows a few more control
characters, in the range above #255.

But exactly that is why he does not need AnsiString at all. His
proocessing can all be done in UnicodeString, right away. If his
incoming data is 8-bit, it can be stored in a byte array instead of an
AnsiString and he'll only have to convert to Unicode once. There is no
need to parse anything BEFORE he converts to Unicode.
--
Rudy Velthuis http://www.rvelthuis.de

"Beware of computer programmers that carry screwdrivers."
-- Leonard Brandwein.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 5:55 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:
Bruce McGee wrote:

Anything between #0 and #31 are non printable characters or binary
data. Can we agree on that?

Actually, no. They are part of ASCII and thus of Unicode. They are no
more "binary data" than 'A' or 'z'.

So how would one define "binary data"? The kind that we shouldn't be using strings for.

--
Regards
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:23 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
So how would one define "binary data"? The kind that we shouldn't be using strings for.

Many tools use the NUL (zero byte) to decide that:
- no NUL's: text
- one or more NUL's: binary data

This makes sense in Delphi too, as some AnsiString functions implicitly assume that the strings are zero-terminated even though the AnsiString documentation does, IIRC, forbid "embedded" NUL's.

- Asbjørn
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 8:43 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Rudy Velthuis (TeamB) wrote:
Bruce McGee wrote:

Anything between #0 and #31 are non printable characters or binary
data. Can we agree on that?

Actually, no. They are part of ASCII and thus of Unicode. They are no
more "binary data" than 'A' or 'z'.

So how would one define "binary data"? The kind that we shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles, TDateTime etc.

AString: AnsiString;
WordArr: array[0..1] of word;
....
WordArr[0] := $DEAD;
WordArr[1] := $BAAD;
AString := 'Two binary words follow:';
SetLength(AString, 28);
CopyMemory(@AString[25], @WordArr, 4);

--
Tom Brunberg
firstname.lastname@welho.com

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 8:50 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles, TDateTime etc.

But not #1 through #4 used as delimiters?

--
Regards
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 8:58 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles, TDateTime etc.

But not #1 through #4 used as delimiters?

No.
The protocol designer has chosen to use these ascii characters as delimiters.

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:35 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:

The protocol designer has chosen to use these ascii characters as
delimiters.

Does having an ASCII code make something text?

Null and Escape have ASCII codes.

--
Regards,
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 7:22 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:

The protocol designer has chosen to use these ascii characters as
delimiters.

Does having an ASCII code make something text?

Null and Escape have ASCII codes.

Bruce, I do understand your dilemma to turn your head right, but I also think that you focus too
much on 'text' as something printable with alphanumerical glyfs and punctuation.

Strings consist of characters. The ascii characters are the characters #0..#127. Other encodings
hold other character sets, as defined by the inventors/publishers.

When certain people cry out: 'Don't use strings to hold binary data', and especially when the
transition to unicode took place, 'characters are not guaranteed to always have a size of one
byte', it must be understood as 'use strings only to hold characters. Characters can be converted
from one encoding to another one. Non-character data would be destroyed by such conversion'.

I already showed you how somebody may have been using strings to hold non-character or 'binary'
data, for example to send over a serial communication link. Maybe just because the serial comm
component was using string type buffers for some strange reason. Or maybe just because composing a
binary stream of bytes as a string was convenient because of the vast number of functions to
manipulate strings.

You probably know the history why the ascii character set has the control characters, so no need to
go into that. But nevertheless, they are characters, they are characters also in unicode, and
conversion from ascii to unicode and vice versa is defined.

To return to the TAB, CR and LF characters. They are invisible (despite what Remy said somwhere)
control characters. They control the printhead position and paper feed mechanisms in printers,
cursor positions in document software etc., so you can see their effect but they are themselves not
visible. The fact that many of the previously important control characters have lost their usage
due to technology changes, doesn't mean that they are not still a part of the ascii (and unicode)
character sets.

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 7:33 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:

When certain people cry out: 'Don't use strings to hold binary data',
and especially when the transition to unicode took place, 'characters
are not guaranteed to always have a size of one byte', it must be
understood as 'use strings only to hold characters. Characters can be
converted from one encoding to another one. Non-character data would
be destroyed by such conversion'.

This is true, but it doesn't change my thinking.

--
Regards,
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 9:57 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:

When certain people cry out: 'Don't use strings to hold binary data',
and especially when the transition to unicode took place, 'characters
are not guaranteed to always have a size of one byte', it must be
understood as 'use strings only to hold characters. Characters can be
converted from one encoding to another one. Non-character data would
be destroyed by such conversion'.

This is true, but it doesn't change my thinking.

Well Bruce,
Then I can only put you in the same catgory as Christoffer:
hopelessly stubborn, don't waste your time more than once.

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 10:34 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:

Well Bruce,
Then I can only put you in the same catgory as Christoffer:
hopelessly stubborn, don't waste your time more than once.

And here I thought I was honestly trying to understand the distinction.

--
Regards
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 11:06 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
This is true, but it doesn't change my thinking.

Perhaps we can try the reverse: convince me that #07 and #27 is binary data while #09 and #13 is "text". I mean, they're just just some byte values in an array...

- Asbjørn
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 1:38 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
When certain people cry out: 'Don't use strings to hold binary data', and especially when the
transition to unicode took place, 'characters are not guaranteed to always have a size of one
byte', it must be understood as 'use strings only to hold characters. Characters can be converted
from one encoding to another one. Non-character data would be destroyed by such conversion'.

When this change was occurring there was explicit discussion regarding the fact that "string" was simply an assignment of a base language datatype. At one time it was the short string, later became ansistring. The "string" could, for any practical purpose, been the name used for some underying "memory object" or "array of words" or "array of bytes" or "array of char" anything else so long as it converted to readable text in user presentation. "String" was a string to be used for text. How that was implemented may vary from time to time.

I already showed you how somebody may have been using strings to hold non-character or 'binary'
data, for example to send over a serial communication link. Maybe just because the serial comm
component was using string type buffers for some strange reason. Or maybe just because composing a
binary stream of bytes as a string was convenient because of the vast number of functions to
manipulate strings.

When the change to UNICODE was implemented many of us (myself included) asked and were assured that the (then currently defined) "string" of ansistring would remain unmolested. Like the shortstring before it, you could still use it so long as you didn't call it "string". If you needed ansistring, just call it ansistring! That data type (call it Phred for all I care) contained a string of bytes that was interpreted, and displayed, outside the ansistring storage boundary based on code pages and other things that mattered little to the internal data. "Binary" data could be rendered based on a code page, but if you didn't render it then you didn't care what page was used. As you mention, the vast number of functions to manipulate strings were extraordinarily useful whether the data were characters or bytes of binary data.

All that said, the point (again) is this: Ansistring, like shortstring before, became a part of the core language. Ansistring is a core datatype with a large array of functions in the runtime. The question is whether Delphi is going to require users to rewrite existing, working, code on account of changes to a core datatype. If so, the question extends to "can you trust Delphi with your code?". I certainly hope so but, cheerleaders aside, the question remains.

Dan
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 9:08 AM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:

All that said, the point (again) is this: Ansistring, like shortstring before, became a part of
the core language. Ansistring is a core datatype with a large array of functions in the runtime.
The question is whether Delphi is going to require users to rewrite existing, working, code on
account of changes to a core datatype. If so, the question extends to "can you trust Delphi with
your code?". I certainly hope so but, cheerleaders aside, the question remains.

It seems to me, that EMBT, with their exclusion of all other string types except UTF-16 encoded
generic string from the mobile platforms, already require a rewrite of parts of users own libraries.
And yes, the 'extension' to the question is indeed something everybody has to decide for themselves.

--
Tom Brunberg
firstname.lastname@welho.com

David Erbas-White

Posts: 202
Registered: 10/11/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 9:07 AM   in response to: Bruce McGee in response to: Bruce McGee
On 10/17/2014 8:50 AM, Bruce McGee wrote:
Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles, TDateTime etc.

But not #1 through #4 used as delimiters?

--
Regards
Bruce McGee
Glooscap Software

#1 through #4 used as delimiters have a discrete meaning, when used as
ASCII characters.

The third byte of a four-byte INT32 has no meaning unless connected with
the other three bytes...

Now, that third byte may, in fact, have the value of #1, #2, #3, or #4,
but it's the CONTEXT that makes it different.

Although I've given a real answer, I'm presuming you were being
facetious in asking the question...

David Erbas-White
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:13 PM   in response to: David Erbas-White in response to: David Erbas-White
David Erbas-White wrote:

Although I've given a real answer, I'm presuming you were being
facetious in asking the question...

Nope. I honestly think of these control characters as binary data.

But it's good that you gave a real answer.

--
Regards,
Bruce McGee
Glooscap Software
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 8:26 AM   in response to: Bruce McGee in response to: Bruce McGee
Am 18.10.2014 03:13, schrieb Bruce McGee:
David Erbas-White wrote:

Although I've given a real answer, I'm presuming you were being
facetious in asking the question...

Nope. I honestly think of these control characters as binary data.

But it's good that you gave a real answer.

Hello,

those control chars are valid ASCII chars. It was quite common in the
DOS aera to send those to your printer to control it, and that even for
otherwise plain texts.

For instance try out to print one page of pure ASCII text on any laser
printer without sending #12 after the text. In quite a lot cases you
will wonder where your page is stuck... ;-)

Greetings

Markus
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:31 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

those control chars are valid ASCII chars.

But does that make them text?

Not being argumentative. I'm giving this a serious think.

--
Regards,
Bruce McGee
Glooscap Software
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 1:43 PM   in response to: Bruce McGee in response to: Bruce McGee
Am 19.10.2014 15:31, schrieb Bruce McGee:
Markus Humm wrote:

those control chars are valid ASCII chars.

But does that make them text?

Not being argumentative. I'm giving this a serious think.

Hello,

because the definition says so and because most if not all of them tell
some interpreter what to do with that text.

What makes a floating point niumber a floating point number?
Inf and NaN are valid floating point values as well and as somebody
wrote there are x such NaN values in the standard.

=> simply get over that little detail. Those special chars are meant to
help processing the text of that string they're in.

Greetings

Markus
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 2:41 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Am 19.10.2014 15:31, schrieb Bruce McGee:
Markus Humm wrote:

those control chars are valid ASCII chars.

But does that make them text?

Not being argumentative. I'm giving this a serious think.

Hello,

because the definition says so and because most if not all of them
tell some interpreter what to do with that text.

I have a hard time getting past thinking of null and escape characters
as "text".

--
Regards,
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 5:07 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
I have a hard time getting past thinking of null and escape characters
as "text".

uses
  System.SysUtils;
 
var
  b: TBytes;
  s: string;
  c: char;
begin
  SetLength(b, 4);
  b[0] := 97; // a
  b[2] := 122; // z
 
  s := TEncoding.ASCII.GetString(b);
 
  WriteLn('"' + s + '"');
  WriteLn;
 
  for c in s do
  begin
    WriteLn(c, ': ', Ord(c));
  end;
 
  ReadLn;
end.


To be fair, I almost expected it to only return the "a".

- Asbjørn
John Treder

Posts: 349
Registered: 8/2/02
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 7:58 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Markus Humm wrote:

Am 19.10.2014 15:31, schrieb Bruce McGee:
Markus Humm wrote:

those control chars are valid ASCII chars.

But does that make them text?

Not being argumentative. I'm giving this a serious think.

Hello,

because the definition says so and because most if not all of them
tell some interpreter what to do with that text.

I have a hard time getting past thinking of null and escape characters
as "text".

Bear down, kid. Keep on ramming your head into that brick wall until I tell you you can quit. <evil g>

--
don't Tred on me
John Furlong

Posts: 96
Registered: 5/25/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 6:14 AM   in response to: Bruce McGee in response to: Bruce McGee
On 20/10/2014 5:41 PM, Bruce McGee wrote:
Markus Humm wrote:

Am 19.10.2014 15:31, schrieb Bruce McGee:
Markus Humm wrote:

those control chars are valid ASCII chars.

But does that make them text?

Not being argumentative. I'm giving this a serious think.

Hello,

because the definition says so and because most if not all of them
tell some interpreter what to do with that text.

I have a hard time getting past thinking of null and escape characters
as "text".
Hi Bruce,

You are right, they are not text.

However, most character encodings I know of (including ASCII, EDCIDIC,
Unicode, ISO88591 ....) all support the encoding of non-text "control
codes". Here is a good description:

http://en.wikipedia.org/wiki/Control_character

The notion that Delphi strings can only contain "text", i.e. characters
that have an associated visual form (glyph) is simply not true. Strings
can (and often do) contain such "control codes", and Delphi strings
handle them just fine.

HTH

John
Brian Hamilton ...

Posts: 556
Registered: 10/14/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 2:45 PM   in response to: Bruce McGee in response to: Bruce McGee

Nope. I honestly think of these control characters as binary data.

it is true that a CR,i.e character #13, can also be mimicked as a byte data, for serial data (i.e send a byte instead of a character), i.e $0d (byte) no problem at all (same for LF, #10, as $0a )

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 9:36 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we shouldn't
be using strings for.

Data that doesn't represent characters. E.g. integers, singles,
TDateTime etc.

But not #1 through #4 used as delimiters?

These are valid ASCII, so valid Unicode, so not binary data, IMO. After
all, I bet you would not see #9, #10 and #13 as "binary data" either.
The other control codes are less usual, but valid control codes too.
--
Rudy Velthuis http://www.rvelthuis.de

"No man's knowledge here can go beyond his experience."
-- John A. Locke
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:28 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:

Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we
shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles,
TDateTime etc.

But not #1 through #4 used as delimiters?

These are valid ASCII, so valid Unicode, so not binary data, IMO.
After all, I bet you would not see #9, #10 and #13 as "binary data"
either. The other control codes are less usual, but valid control
codes too.

I have always considered control characters to be binary.

I know I messed up with my #0 - #31 example, because it includes
whitespace characters, but are you saying that data that includes
control characters such as #01 and #27 can still be considered TEXT and
not binary?

Excuse my being pedantic. This will take a minute to get my head
around, and if I have to backtrack, I want to be REALLY thorough.

--
Regards,
Bruce McGee
Glooscap Software
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 2:46 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce wrote:

I have always considered control characters to be binary.

I know I messed up with my #0 - #31 example, because it includes
whitespace characters, but are you saying that data that includes
control characters such as #01 and #27 can still be considered
TEXT and not binary?

It depends on the nature of the data. Obviously, those values are non-visual
(except for #9, #10, and #13), so they are not TEXT persay. But they are
part of ASCII (and Unicode), and were created at a time when TEXT consoles
were popular, and they do affect TEXT processing. If the data has a TEXTUAL
nature, then they are TEXT characters. If the data has a BINARY nature,
then they are BINARY data. It is all about context.

--
Remy Lebeau (TeamB)
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 2:58 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Bruce wrote:

I have always considered control characters to be binary.

I know I messed up with my #0 - #31 example, because it includes
whitespace characters, but are you saying that data that includes
control characters such as #01 and #27 can still be considered
TEXT and not binary?

It depends on the nature of the data. Obviously, those values are
non-visual (except for #9, #10, and #13), so they are not TEXT
persay. But they are part of ASCII (and Unicode), and were created
at a time when TEXT consoles were popular, and they do affect TEXT
processing. If the data has a TEXTUAL nature, then they are TEXT
characters. If the data has a BINARY nature, then they are BINARY
data. It is all about context.

How about in the context of this thread?

--
Regards,
Bruce McGee
Glooscap Software
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 3:17 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce wrote:

How about in the context of this thread?

In this particular case, it can go either way, depending on what you are
more comfortable with. Since the data is 7bit ASCII only, never going above
#127, and thus has no charset issues, it can be interpretted as either a
purely TEXT protocol, in which case you can convert the whole thing to a
String and parse as needed, or it can be interpreted as a BINARY protocol
with TEXT portions, in which case you have to extract the TEXT pieces between
the BINARY delimiters and process them as Strings as needed. Personally,
given the nature of the data shown, I would lean towards a TEXT protocol,
it is easier to work with.

--
Remy Lebeau (TeamB)
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 8:44 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Bruce wrote:

How about in the context of this thread?

In this particular case, it can go either way, depending on what you
are more comfortable with. Since the data is 7bit ASCII only, never
going above #127, and thus has no charset issues, it can be
interpretted as either a purely TEXT protocol, in which case you can
convert the whole thing to a String and parse as needed, or it can be
interpreted as a BINARY protocol with TEXT portions, in which case
you have to extract the TEXT pieces between the BINARY delimiters and
process them as Strings as needed. Personally, given the nature of
the data shown, I would lean towards a TEXT protocol, it is easier to
work with.

Thanks for your input.

I've mulled this over and I still think of this as mixing binary and
text. Whether it's a binary protocol that includes text or a text
protocol that happens to include non-text (binary) characters.

I've made a distinction between text and binary data even before I
started using Delphi. Essentially anything you would need a hex editor
to view/change.

In this particular case, the protocol uses non-text bytes as delimiters
precisely because they could never occur in text.

Which is all beside the point since the OP's problem can be solved with
AnsiStrings, Unicode strings or arrays of bytes.

--
Regards,
Bruce McGee
Glooscap Software
Jouni Aro

Posts: 86
Registered: 9/4/97
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2014 1:33 AM   in response to: Bruce McGee in response to: Bruce McGee
On 26/10/14 05:44, Bruce McGee wrote:
Remy Lebeau (TeamB) wrote:

Bruce wrote:

How about in the context of this thread?

In this particular case, it can go either way, depending on what you
are more comfortable with. Since the data is 7bit ASCII only, never
going above #127, and thus has no charset issues, it can be
interpretted as either a purely TEXT protocol, in which case you can
convert the whole thing to a String and parse as needed, or it can be
interpreted as a BINARY protocol with TEXT portions, in which case
you have to extract the TEXT pieces between the BINARY delimiters and
process them as Strings as needed. Personally, given the nature of
the data shown, I would lean towards a TEXT protocol, it is easier to
work with.

Thanks for your input.

I've mulled this over and I still think of this as mixing binary and
text. Whether it's a binary protocol that includes text or a text
protocol that happens to include non-text (binary) characters.

I've made a distinction between text and binary data even before I
started using Delphi. Essentially anything you would need a hex editor
to view/change.

In this particular case, the protocol uses non-text bytes as delimiters
precisely because they could never occur in text.

Which is all beside the point since the OP's problem can be solved with
AnsiStrings, Unicode strings or arrays of bytes.

One could say that text is what you can use in email or forum posts:
binary needs uu- or base64-encoding to be properly transmitted, even
though it would be just plain 7-bit ASCII.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2014 4:32 AM   in response to: Jouni Aro in response to: Jouni Aro
Jouni Aro wrote:

One could say that text is what you can use in email or forum posts:
binary needs uu- or base64-encoding to be properly transmitted, even
though it would be just plain 7-bit ASCII.

The rule of thumb I've used since I was parsing protocols for digital phones in Clipper (that was a fun project) was stuff that I can show to the user vs delimiters or encoded data.

Not always comprehensive, but not a bad starting point. I have never bought in to the "everything is text" or "everything is binary" way of thinking.

--
Regards
Bruce McGee
Glooscap Software
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 3:49 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
If the data has a TEXTUAL
nature, then they are TEXT characters. If the data has a BINARY nature,
then they are BINARY data. It is all about context.

That can't be true.

Data is either Text or Binary, each having their own data type. Context has nothing to do with it. I read that right here in this forum, so it must be correct.

Dan
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:06 PM   in response to: Dan Barclay in response to: Dan Barclay
Dan wrote:

That can't be true.

It is true. I deal with it all the time.

Data is either Text or Binary

Yes, but who is to say that a given block of data contains only one type
of data in it? You can have text data and binary data in the same memory
block. Again, all about context, where the data came from, how the data
is being used.

--
Remy Lebeau (TeamB)
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:11 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Dan wrote:

That can't be true.

It is true. I deal with it all the time.

Data is either Text or Binary

Yes, but who is to say that a given block of data contains only one type
of data in it? You can have text data and binary data in the same memory
block. Again, all about context, where the data came from, how the data
is being used.

I thought that at one time, until Rudy clarified it for me. I'd been confused for 40 years, until just recently learning how stupid I'd been for allowing those things to mix. I am saved from my old wicked ways (though what I do in the privacy of my own apps is my business).

HTH.

Dan
Jouni Aro

Posts: 86
Registered: 9/4/97
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:29 PM   in response to: Dan Barclay in response to: Dan Barclay
On 18/10/14 02:11, Dan Barclay wrote:
Remy Lebeau (TeamB) wrote:
Dan wrote:

That can't be true.

It is true. I deal with it all the time.

Data is either Text or Binary

Yes, but who is to say that a given block of data contains only one type
of data in it? You can have text data and binary data in the same memory
block. Again, all about context, where the data came from, how the data
is being used.

I thought that at one time, until Rudy clarified it for me. I'd been confused for 40 years, until just recently learning how stupid I'd been for allowing those things to mix. I am saved from my old wicked ways (though what I do in the privacy of my own apps is my business).

Put your strings in the bin and forget the con-text ;)
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:49 PM   in response to: Jouni Aro in response to: Jouni Aro
Jouni Aro wrote:

Put your strings in the bin and forget the con-text ;)

It beats putting bins in your strings.

--
Regards,
Bruce McGee
Glooscap Software
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 9:54 PM   in response to: Jouni Aro in response to: Jouni Aro
Jouni Aro wrote:
On 18/10/14 02:11, Dan Barclay wrote:

I thought that at one time, until Rudy clarified it for me. I'd been confused for 40 years, until just recently learning how stupid I'd been for allowing those things to mix. I am saved from my old wicked ways (though what I do in the privacy of my own apps is my business).

Put your strings in the bin and forget the con-text ;)

Trouble is, I don't know what a string is. I thought I did.

FWIW, "strings" will change definition again. They're all binary... the only difference between all the flavors is what is done to the binary as they move in and out of their "string" container.

Or maybe not. <shrug>

Dan
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 1:45 AM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:

Remy Lebeau (TeamB) wrote:
Dan wrote:

That can't be true.

It is true. I deal with it all the time.

Data is either Text or Binary

Yes, but who is to say that a given block of data contains only one
type of data in it? You can have text data and binary data in the
same memory block. Again, all about context, where the data came
from, how the data is being used.

I thought that at one time, until Rudy clarified it for me.

Nonsense. If I talk about binary data, then I mean data that can not be
considered text, that can not be converted into differetn encodings.

Of coutse context plays a role. A byte can for instance be an ASCII
character, or the first byte of an integer or a double. The first is
text, the rest is not.

--
Rudy Velthuis http://www.rvelthuis.de

"I know that there are people in this world who do not love
their fellow human beings, and I hate people like that."
-- Tom Lehrer
Steve Thackery

Posts: 151
Registered: 4/29/06
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 4:42 AM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:

Data is either Text or Binary, each having their own data type.

I think at this point some people in this thread have painted
themselves into a corner.

The point is, ALL computer data is binary at the bottom level, and that
includes all data that represents text. It is a false dichotomy to
separate "binary" and "text" data.

Rather, the concept of whether it is text or something else occurs at
the next level up, conceptually speaking. All data is binary, and all
binary data represents something.

What it represents might be text, numbers, instructions, state
information, etc. By asking "Is it text or binary?" we are obscuring
the real situation, rather than shedding light on it. Rather than
asking "Is it text or binary" we should be asking "Is it text or
numbers? Is it text or instructions? Is it text or state
information?" And so on.

In other words, don't lump "non-text" into a generic "binary".
Consider it for what it actually is, and it is clear that the strategy
is, or usually should be, different for each case. In particular, it
is immediately obvious that a lot of data is a mixture of different
representations.

ASCII is a case in point. Some of the binary data represents printable
characters; some represents control instructions; some represents state
information (e.g. ACK).

The rut we're in, of insisting that data is either "binary" or "text",
is first of all conceptually wrong (it's all binary: text is one
possibility of what it might represent at the next layer up); but
secondly traps us into a limited way of thinking when in reality binary
data may - and often does - represent a messy mixture of different
types of information.

Keep the conceptual layers separate. Ask what each piece of data
represents. Use the appropriate tools for the type it represents.

--
SteveT
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 8:31 AM   in response to: Steve Thackery in response to: Steve Thackery
Am 18.10.2014 13:42, schrieb Steve Thackery:

[snip]


The rut we're in, of insisting that data is either "binary" or "text",
is first of all conceptually wrong (it's all binary: text is one
possibility of what it might represent at the next layer up); but
secondly traps us into a limited way of thinking when in reality binary
data may - and often does - represent a messy mixture of different
types of information.

Keep the conceptual layers separate. Ask what each piece of data
represents. Use the appropriate tools for the type it represents.

Well said!

Greetings

Markus
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 9:31 PM   in response to: Steve Thackery in response to: Steve Thackery
Steve Thackery wrote:
Dan Barclay wrote:

Data is either Text or Binary, each having their own data type.

I think at this point some people in this thread have painted
themselves into a corner.

The point is, ALL computer data is binary at the bottom level, and that
includes all data that represents text. It is a false dichotomy to
separate "binary" and "text" data.

Ya think?

Apparently, while we weren't looking, somebody changed all that. <shrug> At least for them.

Dan
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 5:29 AM   in response to: Dan Barclay in response to: Dan Barclay
Dan Barclay wrote:
Steve Thackery wrote:
The point is, ALL computer data is binary at the bottom level, and that
includes all data that represents text. It is a false dichotomy to
separate "binary" and "text" data.

Ya think?

Apparently, while we weren't looking, somebody changed all that. <shrug> At least for them.

I think you're both missing the point. Yes it's all binary in the end, but the thing is, sometimes we care about the bits, other times we care about what they represent.

If you have a regular 32bit integer, it could be a binary flag in which case it matters how the numerical value is encoded in binary. Or you could simply be interested in the numerical value itself, in which case it's perfectly valid to convert it to a IEEE 754 double precision floating point type, as there is no loss.

I view text and "binary data" in the same way. With binary data we care about the bits, and we can't mess around with the bits without changing the meaning of the data. With text we care about the characters (including control characters), whatever their encoding may be.

- Asbjørn
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 5:39 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:
I view text and "binary data" in the same way. With binary data we care about the bits, and we can't mess around with the bits without changing the meaning of the data. With text we care about the characters (including control characters), whatever their encoding may be.

And just to make it clear, in the context of the original post:
- the CRC algorithm cares about the bits and needs to operate on the binary data.
- the protocol (as seen) is textual and can preferably be treated as text, thus converted to a convenient encoding (ie unicodestring) before further processing.

- Asbjørn
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:12 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:

And just to make it clear, in the context of the original post:
- the CRC algorithm cares about the bits and needs to operate on the
binary data. - the protocol (as seen) is textual and can preferably
be treated as text, thus converted to a convenient encoding (ie
unicodestring) before further processing.

I still have a hard time thinking of the control characters as text.

--
Regards,
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:23 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
Asbjørn Heid wrote:

- the protocol (as seen) is textual and can preferably
be treated as text, thus converted to a convenient encoding (ie
unicodestring) before further processing.

I still have a hard time thinking of the control characters as text.

Think of them as Inf or NaN in IEEE 754. They're both valid floating point "numbers" as such but they don't represent actual numbers.

Same with control characters. They're valid characters as far as the encoding in concerned, but they don't represent actual text. Wikipedia has a nice formulation I think[1]: "Many Unicode control characters are used to control the interpretation or display of text, but these characters themselves have no visual or spatial representation".

[1]: http://en.wikipedia.org/wiki/Unicode_control_characters

- Asbjørn
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:33 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:

Bruce McGee wrote:

I still have a hard time thinking of the control characters as text.

Think of them as Inf or NaN in IEEE 754. They're both valid floating
point "numbers" as such but they don't represent actual numbers.

This seems to be different.

--
Regards,
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:41 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
Think of them as Inf or NaN in IEEE 754. They're both valid floating
point "numbers" as such but they don't represent actual numbers.

This seems to be different.

How so? Especially NaN is a "messaging number". It doesn't represent a number, but a message/signal. Similarly (to me) the control characters are "messaging characters". They don't represent actual characters but messages, such as "line break here, please" or "yo, end of file, time to stop".

- Asbjørn
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:48 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:

Similarly (to me) the control
characters are "messaging characters". They don't represent actual
characters but messages, such as "line break here, please" or "yo,
end of file, time to stop".

Line break I can see. It's like other whitespace characters.

Escape, on the other hand...

--
Regards,
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:59 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:
Asbjørn Heid wrote:

Similarly (to me) the control
characters are "messaging characters". They don't represent actual
characters but messages, such as "line break here, please" or "yo,
end of file, time to stop".

Line break I can see. It's like other whitespace characters.

Escape, on the other hand...

You're essentially arguing "why do we have N control characters instead of M", where M < N. There are a given number of control characters in ASCII, why they were defined they way they were is a moot point at this stage. Heck Unicode even defined control characters for signaling different languages (though later deprecated).

For what it's worth IEEE 754 has 8388608 different NaNs (although they all mean one of two things).

- Asbjørn
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 7:26 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:

Bruce McGee wrote:
Asbjørn Heid wrote:

Similarly (to me) the control
characters are "messaging characters". They don't represent actual
characters but messages, such as "line break here, please" or "yo,
end of file, time to stop".

Line break I can see. It's like other whitespace characters.

Escape, on the other hand...

You're essentially arguing "why do we have N control characters
instead of M", where M < N.

I'm arguing that whitespace characters can be considered text, but I
have trouble getting my head around calling control characters, which I
have always considered to be binary, to be text.

Baking my noodle, if you will.

--
Regards,
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 7:45 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Asbjørn Heid wrote:

Bruce McGee wrote:
Asbjørn Heid wrote:

Similarly (to me) the control
characters are "messaging characters". They don't represent actual
characters but messages, such as "line break here, please" or "yo,
end of file, time to stop".

Line break I can see. It's like other whitespace characters.

Escape, on the other hand...

You're essentially arguing "why do we have N control characters
instead of M", where M < N.

I'm arguing that whitespace characters can be considered text, but I
have trouble getting my head around calling control characters, which I
have always considered to be binary, to be text.

Bruce,
In addition to what I said in another reponse, the sooner you accept that strings hold characters
and character sets are what they are defined to be, the sooner the pieces will come nicely together.

--
Tom Brunberg
firstname.lastname@welho.com
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 7:34 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:

Bruce,
In addition to what I said in another reponse, the sooner you accept
that strings hold characters and character sets are what they are
defined to be, the sooner the pieces will come nicely together.

That's my sticking point. Strings hold text.

--
Regards,
Bruce McGee
Glooscap Software
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 1:24 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

That's my sticking point. Strings hold text.

Just as floating point numbers hold numbers...

- Asbjørn
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 8:51 AM   in response to: Asbjørn Heid in response to: Asbjørn Heid
Asbjørn Heid wrote:
Bruce McGee wrote:

That's my sticking point. Strings hold text.

Just as floating point numbers hold numbers...

Except when the hold dates <lol>.

Or when 8 bytes of memory are put into a "string of bytes"... a bucket o bits, in which a row of bits strung together may be moved somewhere as pulses and still represent a double parading as a date.

Or maybe I was just dreaming that.

Dan
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 5:15 AM   in response to: Bruce McGee in response to: Bruce McGee
"Bruce McGee" wrote on Sun, 19 Oct 2014 19:34:28 -0700:

Tom Brunberg wrote:

Bruce,
In addition to what I said in another reponse, the sooner you accept
that strings hold characters and character sets are what they are
defined to be, the sooner the pieces will come nicely together.

That's my sticking point. Strings hold text.

No, they CAN hold text. And besides, text is however you define it
for the given purpose. Is a zero-width space "text?" It's not
printable or visible and only used to tell a formatting algorithm
where a line of characters can be wrapped in a language that does not
use spaces between words. Is that binary data or text? It's Unicode
and quite necessary in a "plain text" string of characters of Thai.

http://www.joelonsoftware.com/articles/Unicode.html
<<<The Single Most Important Fact About Encodings: If you completely
forget everything I just explained, please remember one extremely
important fact. It does not make sense to have a string without
knowing what encoding it uses. You can no longer stick your head in
the sand and pretend that "plain" text is ASCII.>>>

While most trivial projects can behave as if encoding doesn't matter,
it does.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com

Wayne Niddery

Posts: 791
Registered: 4/14/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 9:29 AM   in response to: Bruce McGee in response to: Bruce McGee
"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698085 at forums dot embarcadero dot com...

Line break I can see. It's like other whitespace characters.

I'm arguing that whitespace characters can be considered text, but I
have trouble getting my head around calling control characters, which I
have always considered to be binary, to be text.

Why do you allow for line break then as "text"? It is a control character
too - it physically causes a printer or screen display to move to the next
line, it is not "printable" in any other sense. How is it different than a
carriage return #13- named from the days of manual typewriters - moves the
text point to beginning of line, or BEL #7 literally rings the bell, which
on a typewriter let you know you were almost at the end of a line, etc?

While it may seem antiquated now, when ASCII first came about there had to
be someway to signal a printer or a display to do more than simply print the
next character, so they simply reserved the first 31 values for that
purpose.

--
Wayne Niddery
"You know what they call alternative medicine that has been proven to work?
Medicine." - Tim Minchin

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 2:14 PM   in response to: Wayne Niddery in response to: Wayne Niddery
Wayne Niddery wrote:

Why do you allow for line break then as "text"?

Whitespace character.

--
Regards,
Bruce McGee
Glooscap Software
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 1:33 PM   in response to: Bruce McGee in response to: Bruce McGee
Am 20.10.2014 23:14, schrieb Bruce McGee:
Wayne Niddery wrote:

Why do you allow for line break then as "text"?

Whitespace character.

Not really. Line feed comes from teletypes and printers with some moving
head which print line for line.

CR byte is for moving the head to the most left position then and LF is
for advancing the paper for one row.

That's not printable text eiter but accepted by you.
Now let's get to accept chr(12) as well which is form feed.

It sort of creates white space too: the rest of the page you printed on
becomes to whitespace and if you continute to print you start the next page.

We can continue with that. e.g. some printer languages use chr(27) (yes,
ESC) as the start of command character. The next few characters are the
actual command (which could be to move the print head to some position
thus creating white space) and its parameters.

Greetings

Markus
Wayne Niddery

Posts: 791
Registered: 4/14/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 8:27 AM   in response to: Bruce McGee in response to: Bruce McGee
"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698294 at forums dot embarcadero dot com...
Wayne Niddery wrote:

Why do you allow for line break then as "text"?

Whitespace character.

Which occurs by, originally, moving the print head without printing. So the
same applies to tab, backspace, formfeed, and others that allow you to
change the position of the print head before printing visible characters.
The escape character has been used by many printers to indicate you are
about to send other formatting character codes combinations, for example, to
use a different font, or to underline, etc.

There is no such thing as a "whitespace" character except for the explicit
space (#32) character but even that is really a control character because it
does not print any text, it removes it then moves the printhead/cursor
forward one position - the exact complement of #127 - destructive
backspace - which it moves the printhead / cursor backward then removes any
character at that position - and which everyone agrees is a "control"
character, not text.

--
Wayne Niddery
"You know what they call alternative medicine that has been proven to work?
Medicine." - Tim Minchin

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 9:11 AM   in response to: Wayne Niddery in response to: Wayne Niddery
Wayne Niddery wrote:

"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698294 at forums dot embarcadero dot com...
Wayne Niddery wrote:

Why do you allow for line break then as "text"?

Whitespace character.

Which occurs by, originally, moving the print head without printing.
So the same applies to tab, backspace, formfeed, and others that
allow you to change the position of the print head before printing
visible characters. The escape character has been used by many
printers to indicate you are about to send other formatting character
codes combinations, for example, to use a different font, or to
underline, etc.

There is no such thing as a "whitespace" character except for the
explicit space (#32) character but even that is really a control
character because it does not print any text, it removes it then
moves the printhead/cursor forward one position - the exact
complement of #127 - destructive backspace - which it moves the
printhead / cursor backward then removes any character at that
position - and which everyone agrees is a "control" character, not
text.


Here is what I think of as whitespace characters.

http://en.wikipedia.org/wiki/Whitespace_character

--
Regards,
Bruce McGee
Glooscap Software
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 1:56 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce,

| Here is what I think of as whitespace characters.
|
| http://en.wikipedia.org/wiki/Whitespace_character

Ditto.

--

Q

1.19.1.372 (Q's Broken Toolbar.)

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 6:19 PM   in response to: Quentin Correll in response to: Quentin Correll
Quentin Correll wrote:

Bruce,

Here is what I think of as whitespace characters.

http://en.wikipedia.org/wiki/Whitespace_character

Ditto.

Don't take it the wrong way Q, but I don't know if you agreeing with me
on this helps or hurts my position. :)

--
Regards,
Bruce McGee
Glooscap Software
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2014 10:50 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce,

| Don't take it the wrong way Q, but I don't know if you agreeing with
| me on this helps or hurts my position. :)

LOL!

--

Q

1.19.1.372 (Q's Broken Toolbar.)

Brian Hamilton ...

Posts: 556
Registered: 10/14/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2014 12:53 PM   in response to: Wayne Niddery in response to: Wayne Niddery
might be better to think of all of them as control characters

i.e A is a control character to tell the printer to output A

i.e you could probably send the binary equivalent to a printer and it will still print out A
(just as you can send the binary equivalent for serial port data)
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 2:16 PM   in response to: Wayne Niddery in response to: Wayne Niddery
Wayne Niddery wrote:

While it may seem antiquated now, when ASCII first came about there
had to be someway to signal a printer or a display to do more than
simply print the next character, so they simply reserved the first 31
values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

--
Regards,
Bruce McGee
Glooscap Software
John Treder

Posts: 349
Registered: 8/2/02
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 8:03 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Wayne Niddery wrote:

While it may seem antiquated now, when ASCII first came about there
had to be someway to signal a printer or a display to do more than
simply print the next character, so they simply reserved the first 31
values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Backwards, Bruce.
I consider anything in a string variable that happens to have an ASCII code, to be text.
I consider anything in a variable of some other type, if that variable expects byte-size data units, and that item happens to be an ASCII code, well, maybe it's to be interpreted that way or maybe not. Depends on how the variable is defined.

--
Tredmill
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2014 4:01 PM   in response to: John Treder in response to: John Treder
John Treder wrote:

Bruce McGee wrote:

Wayne Niddery wrote:

While it may seem antiquated now, when ASCII first came about
there had to be someway to signal a printer or a display to do
more than simply print the next character, so they simply
reserved the first 31 values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Backwards, Bruce.
I consider anything in a string variable that happens to have an
ASCII code, to be text. I consider anything in a variable of some
other type, if that variable expects byte-size data units, and that
item happens to be an ASCII code, well, maybe it's to be interpreted
that way or maybe not. Depends on how the variable is defined.

Sounds like the justification I've heard for using strings as binary
buffers.

I'm kind of waiting to hear Wayne's answer.

--
Regards,
Bruce McGee
Glooscap Software
Wayne Niddery

Posts: 791
Registered: 4/14/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 8:30 AM   in response to: Bruce McGee in response to: Bruce McGee
"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698295 at forums dot embarcadero dot com...

While it may seem antiquated now, when ASCII first came about there
had to be someway to signal a printer or a display to do more than
simply print the next character, so they simply reserved the first 31
values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Only if it is in a string type variable. Otherwise it is some other type of
data, not text.

--
Wayne Niddery
"You know what they call alternative medicine that has been proven to work?
Medicine." - Tim Minchin

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 9:13 AM   in response to: Wayne Niddery in response to: Wayne Niddery
Wayne Niddery wrote:

"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698295 at forums dot embarcadero dot com...

While it may seem antiquated now, when ASCII first came about there
had to be someway to signal a printer or a display to do more than
simply print the next character, so they simply reserved the first
31 >> values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Only if it is in a string type variable. Otherwise it is some other
type of data, not text.


This is the leap I can't make.

Being able to put non-text characters into a string doesn't make it
text. That's using a string as a binary buffer.

The made up protocol is a perfect example. Some text delimited by
non-text (binary) bytes.

--
Regards,
Bruce McGee
Glooscap Software
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 12:25 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Wayne Niddery wrote:

"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698295 at forums dot embarcadero dot com...

While it may seem antiquated now, when ASCII first came about there
had to be someway to signal a printer or a display to do more than
simply print the next character, so they simply reserved the first
31 >> values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Only if it is in a string type variable. Otherwise it is some other
type of data, not text.


This is the leap I can't make.

This is the leap you should make, the sooner the better.

Being able to put non-text characters into a string doesn't make it
text. That's using a string as a binary buffer.

Strings hold characters. Some characters represent text, some don't.
Unicode has a great deal of characters that can't be spelled as text,
wingdings and similar and of course also the ASCII characters.
For example:
http://jrgraphix.net/r/Unicode/25A0-25FF

The made up protocol is a perfect example. Some text delimited by
non-text (binary) bytes.

You interpretation is wrong. The correct one is:
Some text delimited by control characters .

--
Tom Brunberg
firstname.lastname@welho.com

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 8:36 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:

You interpretation is wrong. The correct one is:
Some text delimited by control characters .

After a bunch of thought, I still can't agree. You probably won't agree
with my non-agreement, but we're going to have to agree to disagree.

I'll continue to give it more thought, though.

--
Regards,
Bruce McGee
Glooscap Software
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 12:35 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Wayne Niddery wrote:

"Bruce McGee" <bmcgee at glooscap dot com> wrote in message
news:698295 at forums dot embarcadero dot com...

While it may seem antiquated now, when ASCII first came about
there >> had to be someway to signal a printer or a display to do
more than >> simply print the next character, so they simply
reserved the first 31 >> values for that purpose.

I know.

Do you consider anything with an ASCII code to be "text"?

Only if it is in a string type variable. Otherwise it is some other
type of data, not text.


This is the leap I can't make.

Ok, a single byte can not be identified as text or binary. It is the
combination of many bytes that make it text or not. If there is text
and it contains some control characters that can be considered text
(#1..#31), I would still call it text.

But I do see why you consider only some control characters (#9, #10,
#13. perhaps #12 too) text and the rest not. But do note that they are
considered valid Unicode and that there are control characters above
U+00FF in Unicode too.
--
Rudy Velthuis http://www.rvelthuis.de

"I was under medication when I made the decision to burn the
tapes."
-- Richard Nixon
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 1:54 AM   in response to: Steve Thackery in response to: Steve Thackery
Steve Thackery wrote:

Dan Barclay wrote:

Data is either Text or Binary, each having their own data type.

I think at this point some people in this thread have painted
themselves into a corner.

The point is, ALL computer data is binary at the bottom level, and
that includes all data that represents text. It is a false dichotomy
to separate "binary" and "text" data.

It is not a false dichotomy when we speak about strings, IMO. If I
speak about "binary data", especially in the context of strings, I mean
any data that is NOT TEXT. Text can be stored in several encodings and
byte sizes and it can be converted to the standard string type
(UnicodeString) without losing its meaning and contents.

All non-text (or binary) data can not be converted like that without
losing its meaning.

So you are right, the real dichotomy is between text and non-text, but
I simply use the term binary for anything that does not belong in a
string, and ISTM that most people understood that.

--
Rudy Velthuis http://www.rvelthuis.de

"Don't speak unless you can improve on the silence."
-- Spanish proverb

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 8:28 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 17.10.2014 23:46, schrieb Remy Lebeau (TeamB):
Bruce wrote:

I have always considered control characters to be binary.

I know I messed up with my #0 - #31 example, because it includes
whitespace characters, but are you saying that data that includes
control characters such as #01 and #27 can still be considered
TEXT and not binary?

It depends on the nature of the data. Obviously, those values are non-visual
(except for #9, #10, and #13), so they are not TEXT persay. But they are
part of ASCII (and Unicode), and were created at a time when TEXT consoles
were popular, and they do affect TEXT processing. If the data has a TEXTUAL
nature, then they are TEXT characters. If the data has a BINARY nature,
then they are BINARY data. It is all about context.

--
Remy Lebeau (TeamB)

Hello,

in DOS times most of these chars even had a displayable representation.
Amopng those where the 4 suits of cards, a symbol for male and one for
female, a musical note and others (like the paragraph sign used by Word
if you enable the option to show all tabs and paragraphs in your
formatting).

Greetings

Markus
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 1:40 PM   in response to: Markus Humm in response to: Markus Humm
"Markus Humm" wrote on Sat, 18 Oct 2014 08:28:57 -0700:

in DOS times most of these chars even had a displayable representation.

Yuep:

http://people.revoledu.com/kardi/resources/Converter/Image/ASCII.jpg

And NotePad++ has no trouble displaying glyphs for those characters,
though it uses mnemonics instead.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 1:40 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Rudy Velthuis (TeamB) wrote:

Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

So how would one define "binary data"? The kind that we
shouldn't be using strings for.

Data that doesn't represent characters. E.g. integers, singles,
TDateTime etc.

But not #1 through #4 used as delimiters?

These are valid ASCII, so valid Unicode, so not binary data, IMO.
After all, I bet you would not see #9, #10 and #13 as "binary data"
either. The other control codes are less usual, but valid control
codes too.

I have always considered control characters to be binary.

Unicode also knows control characters. And #9, #10 and #13 are also
control characters. They can be considered text.

http://en.wikipedia.org/wiki/Unicode_control_characters
--
Rudy Velthuis http://www.rvelthuis.de

"The only one listening to both sides of an argument
is the neighbor in the next apartment" -- unknown
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 6:14 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:

Bruce McGee wrote:

I have always considered control characters to be binary.

Unicode also knows control characters. And #9, #10 and #13 are also
control characters. They can be considered text.

http://en.wikipedia.org/wiki/Unicode_control_characters

True. These are also whitespace characters.

I have a harder time thinking of characters like #01 or #27 (escape) as
"text", though.

--
Regards,
Bruce McGee
Glooscap Software
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 9:33 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Rudy Velthuis (TeamB) wrote:
Bruce McGee wrote:

Anything between #0 and #31 are non printable characters or binary
data. Can we agree on that?

Actually, no. They are part of ASCII and thus of Unicode. They are
no more "binary data" than 'A' or 'z'.

So how would one define "binary data"? The kind that we shouldn't be
using strings for.

Yes. The kind of data that would be harmed or changed by converting to
to Unicode. You can do that with text, if you use the proper encoding.
Binary data should never be converted to text in any encoding.

--
Rudy Velthuis http://www.rvelthuis.de

"The whole problem with the world is that fools and fanatics are
always so certain of themselves, but wiser people so full of
doubts." -- Bertrand Russell
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 5:49 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Tom Brunberg wrote:
Bruce McGee wrote:

Because he repeatedly writes that there are binary characters embedded in the protocol.

It's also in his made up protocol in the first message of this thread.

I would have expected you to know better. Since you don't, take a look at
http://en.wikipedia.org/wiki/ASCII
Then read through the messages and find the one where he specifically says
that the message consists of only characters in the ascii range, #0..#127.

Anything between #0 and #31 are non printable characters or binary data. Can we agree on that?

No, of course not! A character being printable or not is irrelevant. Non-printable characters are
not any more binary than, say the letter 'A'.
Since I could write f.ex.
AString := 'Bruce!'+CR+LF+'Nice to hear from you.'+CR+LF+'Hope you are well.';
Memo1.Lines.Add(AString);
According to your logic, this is embedding binary data into a string.
Please show me how you do?

On a second thought, this is just noise again. Don't bother.
Or if you want to continue, please open a new topic.

I don't defend Christoffer for being stubborn or not able to admit being wrong
but it serves nobody to throw up pure noise on the wall. You as an advocate for
less noise should really act as an example.

I'll admit to adding to the noise, especially in this case, but I can't let this "it's
impossible" nonsense stand.

Unsupportable statements like this cloud the issue for people who have a legitimate use for 8-bit
strings.

In fact, this guy can't possibly be as dense as he's pretending to be, so it makes me wonder if
he's doing it on purpose.

Anyway, I can't promise less noise, but I'll count to ten before adding to it in this thread.

Then, don't expect less noise from others. (what's the word, hypocrate?, comes to mind)

--
Tom Brunberg
firstname.lastname@welho.com

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 5:58 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
Bruce McGee wrote:

Anything between #0 and #31 are non printable characters or binary data. Can we agree on that?

No, of course not! A character being printable or not is irrelevant. Non-printable characters are
not any more binary than, say the letter 'A'.
Since I could write f.ex.
AString := 'Bruce!'+CR+LF+'Nice to hear from you.'+CR+LF+'Hope you are well.';
Memo1.Lines.Add(AString);
According to your logic, this is embedding binary data into a string.
Please show me how you do?

I gratefully accept your rebuke. CRLF is a good example of where I was wrong.

--
Regards
Bruce McGee
Glooscap Software
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:08 AM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg wrote:
Then, don't expect less noise from others. (what's the word, hypocrate?, comes to mind)

We can be hypocrites together, oh noisy one.

--
Regards
Bruce McGee
Glooscap Software
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:25 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Get that - IT IS NOT BINARY DATA.

It is in fact an ASCII string.

Combined with binary data.

Not in his case. #1..#31 are Unicode too, with the same meaning. That
is why it is so easy to show he doesn't need AnsiString at all. All the
processing he does can be done in Unicode. He doesn't need to parse in
AnsiString and then convert to Unicode: he can convert to Unicode right
away and then do any processing.

I've shown this, but he simply ignores this and keeps on posting that
it can't be done without AnsiString or without code mimicking
AnsiString. IOW, he closes his eyes for the facts.

--
Rudy Velthuis http://www.rvelthuis.de

"I was playing poker the other night... with Tarot cards.
I got a full house and 4 people died." -- Steven Wright
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:21 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Bruce McGee <bmcgee at glooscap dot com> wrote in news:697664
@forums.embarcadero.com:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to
make changes to your code. We've been warned about it since the
Borland days.

OK - the incoming data IS NOT BINARY DATA.

Exactly, And that is why it is a piece of cake to turn it into Unicode
BEFORE you process it.

UData := TEncoding.ASCII.GetString(Data);

where Data is a byte array containing ASCII and UData is a string
(UnicodeString). And that is not just hot air: I have coded it, it
works and I have posted it. But you obviously ignore any reply that
shows you are wrong.

--
Rudy Velthuis http://www.rvelthuis.de

"If there was a god, he wouldn't let a guy walk right up and
shoot you in the face now would he? That's right, now you get
the picture. Truth burns doesn't it?"
-- Henry Rollins

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:18 AM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee wrote:

Dan Barclay wrote:

Now, do it without rewriting the code...

If you are using 8-bit strings for binary data, you will have to make
changes to your code. We've been warned about it since the Borland
days.

In this case, a trivial chage will do the trick.

Indeed, because the control characters #1..#31 are actually considered
ASCII (and thus Unicode), and not plain binary.

--
Rudy Velthuis http://www.rvelthuis.de

"Let him who takes the Plunge remember to return it by Tuesday."
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:13 AM   in response to: Nick Hodges in response to: Nick Hodges
Nick Hodges <nickhodges at gmail dot com> wrote in news:697632
@forums.embarcadero.com:

Remy Lebeau (TeamB) wrote:

Excuse me? You were given multiple solutions by multiple people
showing how to solve the problem.

And somehow he rejects these by saying "You're just recreating what
AnsiStrings do."

Which was exactly the point.

The original statement was that I need ansi strings.

That remains true, that is the point that people are dismissing as if I
started programming today.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:27 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

The original statement was that I need ansi strings.

And you have been told and shown, many times now, that that is not true.

--
Rudy Velthuis http://www.rvelthuis.de

"The only one listening to both sides of an argument
is the neighbor in the next apartment" -- unknown
Nick Hodges

Posts: 2,414
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:34 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:


The original statement was that I need ansi strings.

And people have shown that you don't.

Why can't you just admit that?

--
Nick
Delphi Programming is Fun
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 8:38 AM   in response to: Christopher Burke in response to: Christopher Burke
Am 17.10.2014 10:13, schrieb Christopher Burke:
Nick Hodges <nickhodges at gmail dot com> wrote in news:697632
@forums.embarcadero.com:

Remy Lebeau (TeamB) wrote:

Excuse me? You were given multiple solutions by multiple people
showing how to solve the problem.

And somehow he rejects these by saying "You're just recreating what
AnsiStrings do."

Which was exactly the point.

The original statement was that I need ansi strings.

That remains true, that is the point that people are dismissing as if I
started programming today.

Hello,

no, not the people are dismissing your point, you're not carefully
reading their samples provided to you:

1. all data of your given protocol specification lies between #0 and
#127, so it's pure ASCII data.

2. all ASCII chars in the range #0-#31 are not printable, but it
doesn't matter as the Unicode specification 1:1 copied the
definitions of ASCII into its first 128 chars.

3. That means that you can use a normal Delphi string (internally
UFT16) and read your data into it as shown using the TEncoding.Ascii
parameter.

4. After that you can do string operations on that unicode string as
you're used to.

Now tell me 3 things about this:

1. did you try this route already? if not why not?

2. Is this route too hard to understand?

3. Is our understanding of your specification flawed in any way?
But that would mean then that it contains either chars > 127 or that
partsof the data is treated like some integer or something like
that. Just because it contains non printable chars (remember: CR+LF
is non printable as well and lies in that range, but text containing
it is not considered as being binary data) it's not binary by ASCII
definition!

Greetings

Markus
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 1:11 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) <no dot spam at no dot spam dot com> wrote in
news:697627 at forums dot embarcadero dot com:

Excuse me? You were given *multiple** solutions by **multiple**
people showing how to solve the problem.

ONE <> Multiple.

I don't consider "you just do X" a solution.

Especially when "X" doesn't work.
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 6:19 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697720 at forums dot embarcadero dot com...
Remy Lebeau (TeamB) <no dot spam at no dot spam dot com> wrote in
news:697627 at forums dot embarcadero dot com:

Excuse me? You were given *multiple** solutions by **multiple**
people showing how to solve the problem.

ONE <> Multiple.

THREE+ == Multiple.
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 8:42 AM   in response to: Christopher Burke in response to: Christopher Burke
Am 17.10.2014 10:11, schrieb Christopher Burke:
Remy Lebeau (TeamB) <no dot spam at no dot spam dot com> wrote in
news:697627 at forums dot embarcadero dot com:

Excuse me? You were given *multiple** solutions by **multiple**
people showing how to solve the problem.

ONE <> Multiple.

I don't consider "you just do X" a solution.

Especially when "X" doesn't work.

Hello,

why do you insist of only receiving one solution?
Different people in this thread have posted solutions!

Have you really read the whole thread?
How do you read posts here? NNTP or Webinterface?
e.g. if using a newsreader (like you seem to do) it might
have got "upset" if there should have been some glitch and
thus "eaten" some posts on your side?

e.g. Remy Lebeau posted a solution on 14th October, 02:02.

Greetings

Markus
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 10:52 AM   in response to: Markus Humm in response to: Markus Humm
Markus wrote:

How do you read posts here? NNTP or Webinterface?

He's using NNTP, per the headers of his messages:

X-Source-Client: nntp
...
User-Agent: Xnews/2009.05.01

--
Remy Lebeau (TeamB)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 1:57 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 18.10.2014 19:52, schrieb Remy Lebeau (TeamB):
Markus wrote:

How do you read posts here? NNTP or Webinterface?

He's using NNTP, per the headers of his messages:

X-Source-Client: nntp
...
User-Agent: Xnews/2009.05.01

Hello,

found that out already as well.
So it could be (under bad circumstances) that his NNTP reader
"swallowed" a few posts.

Greetings

Markus
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:16 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Tom Brunberg <nospam@to.me> wrote in
news:697490 at forums dot embarcadero dot com:

Christopher Burke wrote:

I try to be reasonable, but it seems that doesn't work with you
guys. >> I can verify that to get my stuff into unicode, I require
ansi >> strings.

Why do you keep on claiming you would need AnsiStrings for the
pesented task?

Mainly because I do... seems like a good enough reason to me.

Only ONE person even tried to solve the problem presented

BULLSHIT. I posted two solutions, one which used your example as a base
and which only needed a one-liner to be able to do ALL PROCESSING in
UnicodeString. The other used some of the more advanced string handling
functions to make things a little easier. Also ALL IN UNICODE.

You want to demonstrate that one can't do this without AnsiString and
simply don't accept any solutions that show you are wrong.

--
Rudy Velthuis http://www.rvelthuis.de

"Peace is only possible if men cease to place their happiness
in the possession of things which cannot be shared."
-- Julien Benda
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 5:44 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697463 at forums dot embarcadero dot com...

It is easy enough to verify that claim with code as well.

I can verify that to get my stuff into unicode, I require ansi strings.

If that is still the case, then I think one or more of the following must be
the situation (careful, could be taken as inflammatory):

1)You haven't examined the samples and changes presented
-or-
2)You don't understand the changes to those samples and how to apply the
concepts to your actual code
-or-
3)You have failed to accurately represent your problem in both your sample
and your mini-specification

I asked you directly in one of them "Are the following mods to your example
problematic?".
(https://forums.embarcadero.com/message.jspa?messageID=673954#673954)

You did not answer that I see. If so, please indicate where. If not,
please do answer.

Can you compile the various complete, compileable examples presented, and
explain why what they represent is inapplicable to your situation and/or
incorrect, since they meet/conquer your NO-ANSI string challenge?
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 10:46 AM   in response to: david hoke in response to: david hoke
david hoke <dhoke.nojunk@east-shore.com> wrote in
news:697498 at forums dot embarcadero dot com:

"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697463 at forums dot embarcadero dot com...

It is easy enough to verify that claim with code as well.

I can verify that to get my stuff into unicode, I require ansi
strings.

If that is still the case, then I think one or more of the following
must be the situation (careful, could be taken as inflammatory):

I think the situation is - that people keep saying, I don't need ansi
strings because I can use X, when X is just ansi strings written
differently.

What ever the situation is, I've minimised the use of Ansi strings as far
as I can go and convert to unicode asap.

Anyway, I created this thread (over the original dicussion) to attempt to
get answers, and all I'm getting is more people just moaning and moaing
that YES YOU CAN.

Sorry - but YES YOU CAN isn't enough to alter reality.
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 11:19 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697572 at forums dot embarcadero dot com...

I think the situation is - that people keep saying, I don't need ansi
strings because I can use X, when X is just ansi strings written
differently.

No. The "harder" solution I posted is definitely NOT "ansi strings" written
differently.


What ever the situation is, I've minimised the use of Ansi strings as far
as I can go and convert to unicode asap.

Anyway, I created this thread (over the original dicussion) to attempt to
get answers, and all I'm getting is more people just moaning and moaing
that YES YOU CAN.

No, more than moaning has been done...

Actually compileable code that does NOT use ansi strings, nor rewrite them,
has been presented.


Sorry - but YES YOU CAN isn't enough to alter reality.

More than YES YOU CAN has been presented.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 1:00 PM   in response to: david hoke in response to: david hoke
david wrote:

No. The "harder" solution I posted is definitely NOT "ansi strings"
written differently.

Neither were my examples.

--
Remy Lebeau (TeamB)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 1:30 PM   in response to: Christopher Burke in response to: Christopher Burke
Hello,

you should review this thread better. One person even found flaws in the
implementation you presented which led to your code not being compilable
and if it were to not comply weith your own specification.
This same person provided some implementation as well.

=> please reread all posts of this thread which contain source code.

Greetings

Markus
Asbjørn Heid

Posts: 267
Registered: 11/12/12
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2014 3:41 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:
I think the situation is - that people keep saying, I don't need ansi
strings because I can use X, when X is just ansi strings written
differently.

I don't need gold to be rich, I can use this air here. It's just subatomic particles in a different configuration...

- Asbjørn
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:31 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

david hoke <dhoke.nojunk@east-shore.com> wrote in
news:697498 at forums dot embarcadero dot com:

"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:697463 at forums dot embarcadero dot com...

It is easy enough to verify that claim with code as well.

I can verify that to get my stuff into unicode, I require ansi
strings.

If that is still the case, then I think one or more of the following
must be the situation (careful, could be taken as inflammatory):

I think the situation is - that people keep saying, I don't need ansi
strings because I can use X, when X is just ansi strings written
differently.

WRONG! I have said, often enouzgh, and SHOWED. that you can do all you
do in your sample in UnicodeString as well. No need to write code that
mimicks AnsiString, unless you claim that UnicodeString mimicks
AnsiString. You can do it all in UnicodeString using EXISTING runtime
routines. YOU DO NOT NEED ANY SPECIAL CODE FOR THAT.

And yes, I have posted two example that do exactly that. You IGNORED
them and keep on claiming your nonsense.

--
Rudy Velthuis http://www.rvelthuis.de

"Imagine if every Thursday your shoes exploded if you tied them
the usual way. This happens to us all the time with computers,
and nobody thinks of complaining." -- Jeff Raskin
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:12 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:697418
@forums.embarcadero.com:

Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in
news:697109 >> @forums.embarcadero.com:

Then there is no problem at all. You can do all processing in
UnicodeStrings.

Yeah - I can fly without wings, I can walk through solid walls.

I see you try to be sarcastic. Keep trying.

I try to be reasonable

No, you don't. You refuse to accept the fact that all you want to do is
possible and pretty easy using byte arrays. IOW, you don't want to face
it that several people have already told you that you DON'T NEED
AnsiStrings, despite your claims to the contrary.

--
Rudy Velthuis http://www.rvelthuis.de

"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 12:08 PM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" wrote on Mon, 13 Oct 2014 11:42:17 -0700:

To clarify - ASCII consists of characters 0...127, so the incoming block of
up to 128 CHARACTERS is ASCII.

If that is the case, that makes this really easy. The first 127
Unicode code points map directly to ASCII. You should have zero
issues just using Unicode strings.

If you need to calculate a CRC, do that while it's in a byte array.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 11:55 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rich < &lt;&gt; wrote in news:696690 at forums dot embarcadero dot com:

Quentin Correll wrote:

What's "THe block"?

I figure that's the chunk (block) of data that is sent via the
packet.

I don't know why Christopher says this: "You have an ansi string of
up to 128 bytes". It looks like an array of up to 128 bytes.

I'm sorry, the specification says ASCII string of up to 128
bytes...but anyway it is is an array of up to 128 ASCII characters
(what I like to call a string).

So these characters ar guaranteed to be in the range 0..127? The
"data,data,Flag" part is really just ASCII text, and not some kind of
binary data?

Then what on earth is the problem? Just move your ASCII to Unicode and
do all the processing in Unicode. I'll post an example.

--
Rudy Velthuis http://www.rvelthuis.de

"Grasshopper, look beyond the game, as you look beneath the
surface of the pool to see its depths."
-- Master Po
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:15 AM   in response to: Quentin Correll in response to: Quentin Correll
Quentin Correll wrote:

Christopher,

2. THe block is ...

What's "THe block"?

He probably means "teh block". <g>

--
Rudy Velthuis http://www.rvelthuis.de

"Men and nations behave wisely once they have exhausted all the
other alternatives." -- Abba Eban (1915-2002)
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 1:07 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy,

| | What's "THe block"?
|
| He probably means "teh block". <g>

<g>

--

Q

1.19.1.372 (Q's Broken Toolbar.)
Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 5:55 PM   in response to: Christopher Burke in response to: Christopher Burke
If all this is made of characters from 0 to 255, why should it be a problem if you put them in a unicode string?
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 10:14 PM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd <> wrote in news:696689 at forums dot embarcadero dot com:

If all this is made of characters from 0 to 255, why should it be a
problem if you put them in a unicode string?

There isn't - however getting them requires ansi string functionality.

Matter of fact, the very first thing I do is pick the string apart and put
the resulting data into unicode data strings (and numbers and other stuff).
> Rich <

Posts: 171
Registered: 2/6/09
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 10:34 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

however getting them requires ansi string functionality.

Why?

Matter of fact, the very first thing I do is pick the string apart and put
the resulting data into unicode data strings (and numbers and other stuff).

I don't understand. If you pick the array apart and put the strings in strings and the numbers in numbers etc. What is the problem? The bytes come in from a port of some kind and then are stored as an array of byte.
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2014 11:51 PM   in response to: > Rich < in response to: > Rich <
Rich < &lt;&gt; wrote in news:696705 at forums dot embarcadero dot com:

Christopher Burke wrote:

however getting them requires ansi string functionality.

Why?

Don't ask me - you have the sample above, go for it.

I don't understand.

I know.

:)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 8:18 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

however getting them requires ansi string functionality.

Why?

Don't ask me - you have the sample above, go for it.

We don't have a sample, just a vague problem description. Show us your
code that REQUIRES AnsiStrings, as you claim. Then it is easy to
demonstrate how this can be done without them.

--
Rudy Velthuis http://www.rvelthuis.de

"The optimist proclaims that we live in the best of all
possible worlds; and the pessimist fears this is true."
-- James Branch Cabell
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:19 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696829
@forums.embarcadero.com:

Christopher Burke wrote:

however getting them requires ansi string functionality.

Why?

Don't ask me - you have the sample above, go for it.

We don't have a sample, just a vague problem description. Show us your
code that REQUIRES AnsiStrings, as you claim. Then it is easy to
demonstrate how this can be done without them.

You have a specification above, feel free to ask questions on the spec.

You have data input, and data output requirements, protocol specs and
everything.

I can't show you the code - for a start it isn't mine (It belongs to my
employer), secondly many of the protocols are CiC and thirdly they are way
to weird to make a useful example (too many other non-ansi string issues).
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:21 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Douglas Rudd <> wrote in news:696689 at forums dot embarcadero dot com:

If all this is made of characters from 0 to 255, why should it be a
problem if you put them in a unicode string?

There isn't - however getting them requires ansi string functionality.

NO, IT DOESN'T. Take a look at TEncoding and byte arrays.

--
Rudy Velthuis http://www.rvelthuis.de

"... the cost of adding a feature isn't just the time it takes
to code it. The cost also includes the addition of an obstacle
to future expansion. ... The trick is to pick the features that
don't fight each other." -- John Carmack
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 11:43 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696750
@forums.embarcadero.com:

Christopher Burke wrote:

Douglas Rudd <> wrote in news:696689 at forums dot embarcadero dot com:

If all this is made of characters from 0 to 255, why should it be a
problem if you put them in a unicode string?

There isn't - however getting them requires ansi string functionality.

NO, IT DOESN'T. Take a look at TEncoding and byte arrays.

You keep saying that - yet provide no proof apart from the fact you don't
even know what ASCII is.

So, as I said - you have the example, you have the challenge - care to
actually put your awesomeness to something useful, or just keep spouting
stuff which is just wrong ?
John Frazier


Posts: 726
Registered: 2/17/00
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 8:08 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:
You keep saying that - yet provide no proof apart from the fact you don't
even know what ASCII is.

Seriously? Everybody here knows what ASCII is. Try to be more revealing and friendly when asking for help and you will likely get more favorable responses.
--
John Frazier (Embarcadero Newsgroup Admin)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 9:35 AM   in response to: John Frazier in response to: John Frazier
John Frazier wrote:

Christopher Burke wrote:
You keep saying that - yet provide no proof apart from the fact you
don't even know what ASCII is.

Seriously? Everybody here knows what ASCII is. Try to be more
revealing and friendly when asking for help and you will likely get
more favorable responses.

Well, he is not asking for help, he is asking for people to perform a
task without using AnsiString, in order to prove it is not possible
without AnsiString, which has been his claim all the time.

IOW, he wants people to fail in order to prove his point.

--
Rudy Velthuis http://www.rvelthuis.de

"A clever man commits no minor blunders."
-- Goethe (1749-1832)
John Frazier


Posts: 726
Registered: 2/17/00
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 12:08 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:
John Frazier wrote:

Christopher Burke wrote:
You keep saying that - yet provide no proof apart from the fact you
don't even know what ASCII is.

Seriously? Everybody here knows what ASCII is. Try to be more
revealing and friendly when asking for help and you will likely get
more favorable responses.

Well, he is not asking for help, he is asking for people to perform a
task without using AnsiString, in order to prove it is not possible
without AnsiString, which has been his claim all the time.

IOW, he wants people to fail in order to prove his point.

Yes he does want help (it is not semantics)... to prove his point. But still, you can do so and still be nice and not rude which is my only point.
--
John Frazier (Embarcadero Newsgroup Admin)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 9:23 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696750
@forums.embarcadero.com:

Christopher Burke wrote:

Douglas Rudd <> wrote in news:696689 at forums dot embarcadero dot com:

If all this is made of characters from 0 to 255, why should it
be a >> > problem if you put them in a unicode string?

There isn't - however getting them requires ansi string
functionality.

NO, IT DOESN'T. Take a look at TEncoding and byte arrays.

You keep saying that - yet provide no proof apart from the fact you
don't even know what ASCII is.

So, as I said - you have the example, you have the challenge - care
to actually put your awesomeness to something useful, or just keep
spouting stuff which is just wrong ?

Put my awesomeness to something useful for you, after you talk to me
like that? Oh well, I'll try, as soon as I have the time.

--
Rudy Velthuis http://www.rvelthuis.de

"I am an expert of electricity. My father occupied the chair of
applied electricity at the state prison." -- WC Fields.
Clinton Johnson

Posts: 2
Registered: 4/22/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:27 AM   in response to: Christopher Burke in response to: Christopher Burke
Load your "ansi string" data bytes into a TBytes array and parse it as bytes, that way you avoid the entire unicode utf8,16,2 translation business (and it still works on versions of the compiler that do not support 8 bit data).

You can use the TEncoding class in SysUtils to translate the TBytes into any required available string type after you figure out the locations of the data in the block if you require strings to work with later.

Christopher Burke wrote:
THE ANSI STRING CHALLENGE
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:21 AM   in response to: Clinton Johnson in response to: Clinton Johnson
Clinton Johnson wrote:

Load your "ansi string" data bytes into a TBytes array and parse it
as bytes, that way you avoid the entire unicode utf8,16,2 translation
business (and it still works on versions of the compiler that do not
support 8 bit data).

You can use the TEncoding class in SysUtils to translate the TBytes
into any required available string type after you figure out the
locations of the data in the block if you require strings to work
with later.

Exactly.
--
Rudy Velthuis http://www.rvelthuis.de

"Argue for your limitations, and sure enough they're yours."
-- Richard Bach
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 11:45 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696751
@forums.embarcadero.com:

Exactly.

Exactly nothing, "just parse it"...

I can make Apple pie, I just go to the store and buy some Apple pie.

LOL
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 7:23 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696751
@forums.embarcadero.com:

Exactly.

Exactly nothing, "just parse it"...

Since it is not entirely clear what kind of data you receive, it is
hard to tell how to manage it.

--
Rudy Velthuis http://www.rvelthuis.de

"He can compress the most words into the smallest idea of any
man I know." -- Abraham Lincoln (1809-1865)
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 11:46 AM   in response to: Clinton Johnson in response to: Clinton Johnson
Clinton Johnson <> wrote in news:696719 at forums dot embarcadero dot com:

"after you figure out the
locations of the data in the block if you require strings to work with
later. "

Oh dear,

Recipe for Apple pie:

Ingredients

1 x Apple Pie

Clinton Johnson

Posts: 2
Registered: 4/22/98
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 7:43 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:
Clinton Johnson <> wrote in news:696719 at forums dot embarcadero dot com:

"after you figure out the
locations of the data in the block if you require strings to work with
later. "

Oh dear,

Recipe for Apple pie:

Ingredients

1 x Apple Pie


Let's be clear here Christopher. Are you asking if it is possible to do without ansi strings? Because I outlined the tools you would need to do just that - which answers your question. Yes. Totally possible.

Or did you have some other motive here?
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:30 PM   in response to: Clinton Johnson in response to: Clinton Johnson
Clinton Johnson <> wrote in news:696990 at forums dot embarcadero dot com:

Christopher Burke wrote:
Clinton Johnson <> wrote in news:696719 at forums dot embarcadero dot com:

"after you figure out the
locations of the data in the block if you require strings to work
with later. "

Oh dear,

Recipe for Apple pie:

Ingredients

1 x Apple Pie


Let's be clear here Christopher. Are you asking if it is possible to
do without ansi strings?

You didn't meet the specs sorry. I was trying to be polite and say good
work, however you

- replicated ansi string functionality via state machine (pos/copy)
- did provide a reusable set of tools (not your fault, that is how state
machines are).

That is - you failed.

Is that clearer ?
Uwe Raabe

Posts: 180
Registered: 10/20/00
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:55 AM   in response to: Christopher Burke in response to: Christopher Burke
Am 12.10.2014 um 23:28 schrieb Christopher Burke:
THE ANSI STRING CHALLENGE

I assume you already have a working process dealing with Ansistring? Why
aren't you providing that here and doen't require us to work out an
algorithm for ourselves? It would be far easier to take your existing
code and make it work without Ansistrings than develop the complete
functionality from scratch.

--
Uwe Raabe
Embarcadero MVP
Certified Delphi Master Developer
Uwe's Blog: The Art of Delphi Programming <http://www.uweraabe.de/>
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 11:51 AM   in response to: Uwe Raabe in response to: Uwe Raabe
Uwe Raabe <uwe at uweraabe dot de> wrote in news:696722 at forums dot embarcadero dot com:

Am 12.10.2014 um 23:28 schrieb Christopher Burke:
THE ANSI STRING CHALLENGE

I assume you already have a working process dealing with Ansistring? Why
aren't you providing that here and doen't require us to work out an
algorithm for ourselves?

Because the actual specs and systems in place are WAY to complex, but the
process that involves ANSI strings in the 'challange' are trivial.

pos/copy for the <1>, <2>, <3>, <4>
split (post comma/copy) to extract the comma separated elements.
upcase(flag) to check out which of the two states it is in.
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 1:59 PM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" wrote on Mon, 13 Oct 2014 11:51:32 -0700:

Because the actual specs and systems in place are WAY to complex, but the
process that involves ANSI strings in the 'challange' are trivial.

pos/copy for the <1>, <2>, <3>, <4>
split (post comma/copy) to extract the comma separated elements.
upcase(flag) to check out which of the two states it is in.

I do not see the value in the choice Emb has made to remove support
for Ansistrings, but, all of what you said above seems rather trivial
to me. While using the Ansistrings library is one way to do that,
none of those sound even the least bit difficult to implement in a few
minutes of hand coding with a byte array. What are you not telling
us?

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:31 PM   in response to: Brandon Staggs in response to: Brandon Staggs
Brandon Staggs <nospam@nowhere.invalid> wrote in
news:696925 at forums dot embarcadero dot com:

"Christopher Burke" wrote on Mon, 13 Oct 2014 11:51:32 -0700:

Because the actual specs and systems in place are WAY to complex, but
the process that involves ANSI strings in the 'challange' are
trivial.

pos/copy for the <1>, <2>, <3>, <4>
split (post comma/copy) to extract the comma separated elements.
upcase(flag) to check out which of the two states it is in.

I do not see the value in the choice Emb has made to remove support
for Ansistrings, but, all of what you said above seems rather trivial
to me. While using the Ansistrings library is one way to do that,
none of those sound even the least bit difficult to implement in a few
minutes of hand coding with a byte array. What are you not telling
us?

My argument has always been that ansi strings are required. The fact that
one has to write them yourself, then modify other libraries that depend on
ansi strings to use them - that is the show stopper.
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 7:53 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" wrote on Mon, 13 Oct 2014 21:31:49 -0700:

My argument has always been that ansi strings are required. The fact that
one has to write them yourself, then modify other libraries that depend on
ansi strings to use them - that is the show stopper.

But from what you have shown, ANSI strings are not a requirement. In
fact, based on what you have shown, it would not even occur to me to
try to use ANSI strings at all. Thus, my inquiry about what it is you
haven't included in your requirements.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 7:23 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

pos/copy for the <1>, <2>, <3>, <4>

UnicodeString.Split would do that much better. <g>

split (post comma/copy) to extract the comma separated elements.

UnicodeString.Split again.

upcase(flag) to check out which of the two states it is in.

Well, or simply check for 'Y', 'y', 'N' or 'n'. No need for the upcase.

All that can be done in normal strings (i.e. UnicodeString) too. Where
is the problem? Just convert your ASCII data to Unicode. I assume you
know how to do that, using TEncoding?

--
Rudy Velthuis http://www.rvelthuis.de

"Intellectuals solve problems; geniuses prevent them."
-- Albert Einstein
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 1:11 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

You have an an ascii string of up to 128 bytes long, and is of the
following form

Either

A: <1>sender info<2>data,data,FLAG<3>result info<4>
or
B: <1>sender info<3>result info,FLAG<4>

Now this is a simplified and made up example to show case a few issues
at once.

Your aim, to extract the 4 (or 2) lots of data and also which format (#1
is valid, #2 is error response) into real strings with the following
knowledge.

1. <1> <2> <3> <4> are ascii control characters (SOT,SOH,EOH,EOT for
example - they will always be between 1 and 31 and never 0).
2. THe block is ASCII data and is a single block of data (embedded in
another packet)..
3. The data is in one of two formats, that format based upon the value
of FLAG (Y/y or N/n/E/e).
4. X,Y,Z is comma separated data.
5. You must validate the protocol and generate exceptions if the protcol
is not followed.
6. You must validate <2>XXXX<3> by doing a CRC vs a provided value (from
higher level block).
7. sender info : details of the terminal, user and location that sent
the requed.
8. result info : either result info (e.g. customer leaving today) or
error info (e.g. customer not found).
9. data,data : the core data I require

Your answer will look like either:

VALID: source info, data, data , result info
ERROR: source info, result info
PROTOCOL ERROR: where/why

You must write this using NO ansi strings, nor writing any routines or
code chunks that emulate ansi string functionality. It must be reusable
across multiple cases (up to 10 different external vendor protocols).

Assume you receive an array of bytes 128 bytes long with a number of
bytes used field, or a TBytes etc.

That is - you must prove that ansi strings are NOT required to extract
this data, the intent is not to prove that you can write ansi strings
yourself (that is obviously possible - after all Delphi for desktop has
them).

Thank you


Here's a suggestion. I'm not going to do all your work for you, so figure out yourself the rest.
It demonstartes how you can extract the various ascii data items embedded between control chars
into unicode strings for further processing.


 
TState = (stNothing, stReadSender, stReadData, stReadResult, stEndOfMsg)
 
var
  buffer: TBytes;
  abyte: byte;
  bufindx: integer;
  SenderInfo: string;
  DataStrArr: array[0..3] of string;
  DataStrIndx: integer;
  DataFlag: Char;
  ResultInfo: string;
  State: TState;
 
begin
  bufindx := 0;
  DataStrIndx := 0;
  State := stNothing;
  while (bufindx < 128) and (buffer[bufindx] <> 0) do
  begin
    abyte := buffer[bufindx]
    case abyte of
      <1>: State := stReadSender;
      <2>: begin InitiateCRC; State := stReadData; end;
      <3>: begin ConcludeCRC; State := stReadResult; end;
      <4>: State := stEndOfMsg;
      31..127: begin
        case State of
          stReadSender: SenderInfo := SenderInfo + char(abyte);
          stReadData: 
          begin
            AddToCRC(abyte);
            case abyte of
              Ord('Y'),Ord('y',Ord('N'),Ord('n',Ord('E'),Ord('e'): DataFlag := Char(abyte);
              Ord(','): Inc(DataStrIndx);
              else DataStrArr[DataStrIndx] := DataStrArr[DataStrIndx] + char(abyte);
            end;
          end;
          stReadResult: ResultInfo := ResultInfo + Char(abyte);
        end;
      end;
      else raise ENonAscii;
    end;
    if State = stEndOfMsg then break;
  end;
  if not CRCCheck then raise ECRCFail;
  if not (State = stEndOfMsg) then raise EMsgStructure;
//  Here you now have the meat of the message in
//  SenderInfo, DataStrArr, DataFlag and ResultInfo
//  as unicodestrings for further prcessing
end;
 

--
Tom Brunberg
firstname.lastname@welho.com

Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:07 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Tom Brunberg <nospam@to.me> wrote in news:696723 at forums dot embarcadero dot com:

Here's a suggestion. I'm not going to do all your work for you, so
figure out yourself the rest. It demonstartes how you can extract the
various ascii data items embedded between control chars into unicode
strings for further processing.

 
 
TState = (stNothing, stReadSender, stReadData, stReadResult,
stEndOfMsg) 
 
var
  buffer: TBytes;
  abyte: byte;
  bufindx: integer;
  SenderInfo: string;
  DataStrArr: array[0..3] of string;
  DataStrIndx: integer;
  DataFlag: Char;
  ResultInfo: string;
  State: TState;
 
begin
  bufindx := 0;
  DataStrIndx := 0;
  State := stNothing;
  while (bufindx < 128) and (buffer[bufindx] <> 0) do
  begin
    abyte := buffer[bufindx]
    case abyte of
      <1>: State := stReadSender;
      <2>: begin InitiateCRC; State := stReadData; end;
      <3>: begin ConcludeCRC; State := stReadResult; end;
      <4>: State := stEndOfMsg;
      31..127: begin
        case State of
          stReadSender: SenderInfo := SenderInfo + char(abyte);
          stReadData: 
          begin
            AddToCRC(abyte);
            case abyte of
              Ord('Y'),Ord('y',Ord('N'),Ord('n',Ord('E'),Ord('e'):
              DataFlag := Char(abyte); Ord(','): Inc(DataStrIndx);
              else DataStrArr[DataStrIndx] := DataStrArr[DataStrIndx]
              + char(abyte); 
            end;
          end;
          stReadResult: ResultInfo := ResultInfo + Char(abyte);
        end;
      end;
      else raise ENonAscii;
    end;
    if State = stEndOfMsg then break;
  end;
  if not CRCCheck then raise ECRCFail;
  if not (State = stEndOfMsg) then raise EMsgStructure;
//  Here you now have the meat of the message in
//  SenderInfo, DataStrArr, DataFlag and ResultInfo
//  as unicodestrings for further prcessing
end;
 



Thank you for putting the effort in.

You have in fact created a complex state machine that is not reusable
across the multiple interfaces.

Your state machine does string processing, just in a non-reusable way.

Score : 8/10 (fails on code reuse - and no it isn't your code, state
machines are just that way).
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 12:01 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

Tom Brunberg <nospam@to.me> wrote in news:696723 at forums dot embarcadero dot com:

Here's a suggestion. I'm not going to do all your work for you, so
figure out yourself the rest. It demonstartes how you can extract the
various ascii data items embedded between control chars into unicode
strings for further processing.

Thank you for putting the effort in.

You are welcome, Christopher!

You have in fact created a complex state machine that is not reusable
across the multiple interfaces.

Can't deny lack of reusability.
I've used the method (without conversion to unicode) in real time serial
comm monitoring for a very specific protocol.

Your state machine does string processing, just in a non-reusable way.

The main point was of course that you don't need AnsiString, AnsiChar.

Score : 8/10 (fails on code reuse - and no it isn't your code, state
machines are just that way).

Wow, thanks!

--
Tom Brunberg
firstname.lastname@welho.com

david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 10:47 AM   in response to: Christopher Burke in response to: Christopher Burke
"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:696871 at forums dot embarcadero dot com...

You have in fact created a complex state machine that is not reusable
across the multiple interfaces.

Your state machine does string processing, just in a non-reusable way.

Score : 8/10 (fails on code reuse - and no it isn't your code, state
machines are just that way).

Hmm, seems it is just as reuseable across any interface meeting your
challenge spec., as your example using ansistring with pos().

Or, that your solution with ansistring and pos, is no more useable across
interfaces.

Am I missing something?
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 3:15 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

You have an an ascii string of up to 128 bytes long, and is of the
following form

Either

A: <1>sender info<2>data,data,FLAG<3>result info<4>
or
B: <1>sender info<3>result info,FLAG<4>

You are storing data in AnsiStrings. That is not valid challenge, since
you should NEVER have done that. You should have used byte arrays all
the time.

But I'll try anyway, this evening.

--
Rudy Velthuis http://www.rvelthuis.de

"Invisible Pink Unicorns are beings of awesome mystical power.
We know this because they manage to be invisible and pink at
the same time. Like all religions, the Faith of the Invisible
Pink Unicorns is based upon both logic and faith. We have faith
that they are pink; we logically know that they are invisible
because we can't see them."
-- Steve Eley
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:09 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696744
@forums.embarcadero.com:

You are storing data in AnsiStrings.

No - the external data IS in Ansi strings (ASCII to be precise).

That IS the challenge.

Feel free to store it how ever you please, I've just given you a simulated
and simplified spec, however these specs are ASCII.
Loren Pechtel

Posts: 20
Registered: 3/23/00
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 10:01 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
On Mon, 13 Oct 2014 03:15:25 -0700, Rudy Velthuis (TeamB)
<newsgroups at rvelthuis dot de> wrote:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

You have an an ascii string of up to 128 bytes long, and is of the
following form

Either

A: <1>sender info<2>data,data,FLAG<3>result info<4>
or
B: <1>sender info<3>result info,FLAG<4>

You are storing data in AnsiStrings. That is not valid challenge, since
you should NEVER have done that. You should have used byte arrays all
the time.

But I'll try anyway, this evening.

He's not the one doing it. Someone else is sending ANSI data, he has
to cope wwith it..
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 7:23 AM   in response to: Loren Pechtel in response to: Loren Pechtel
Loren Pechtel wrote:

On Mon, 13 Oct 2014 03:15:25 -0700, Rudy Velthuis (TeamB)
<newsgroups at rvelthuis dot de> wrote:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

You have an an ascii string of up to 128 bytes long, and is of the
following form

Either

A: <1>sender info<2>data,data,FLAG<3>result info<4>
or
B: <1>sender info<3>result info,FLAG<4>

You are storing data in AnsiStrings. That is not valid challenge,
since you should NEVER have done that. You should have used byte
arrays all the time.

But I'll try anyway, this evening.

He's not the one doing it. Someone else is sending ANSI data, he has
to cope wwith it..

ANSI data are just bytes. Where is the problem?

Now, if he said that he can't move to mobile because the library he is
using was never ported to mobile (because they apparently lack the
knowledge to use byte arrays), then I'd agree. But not because of
AnsiStrings. Ansi data does not require AnsiStrings to handle it.

--
Rudy Velthuis http://www.rvelthuis.de

"Give to every other human being every right you claim for
yourself."
-- Robert G. Ingersoll
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 11:27 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy wrote:

Now, if he said that he can't move to mobile because the library he is
using was never ported to mobile (because they apparently lack the
knowledge to use byte arrays), then I'd agree. But not because of
AnsiStrings. Ansi data does not require AnsiStrings to handle it.

Totally agree.

--
Remy Lebeau (TeamB)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 5:01 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

Show us what you have, and I'll do it without AnsiStrings.

--
Rudy Velthuis http://www.rvelthuis.de

"Think my friends! You adulate a stone as Vishnu but you cannot
see God in a fellow man."
-- Sankaracharya
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 7:03 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:
Show us what you have, and I'll do it without AnsiStrings.

For the sake of all our eyes, KEEP YOUR ANSISTRINGS ON.

;)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 7:17 AM   in response to: Dominique Willems in response to: Dominique Willems
Dominique Willems wrote:

Rudy Velthuis (TeamB) wrote:
Show us what you have, and I'll do it without AnsiStrings.

For the sake of all our eyes, KEEP YOUR ANSISTRINGS ON.

;)

LOL!

--
Rudy Velthuis http://www.rvelthuis.de

"Democracy does not guarantee equality of conditions - it only
guarantees equality of opportunity." -- Irving Kristol
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:20 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) <newsgroups at rvelthuis dot de> wrote in news:696762
@forums.embarcadero.com:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

Show us what you have, and I'll do it without AnsiStrings.

I've given you a trivial example, go ahead and do it.

Wait - don't bother, I suspect you teach because you can't do.

One person has already beaten the challenge with a non-reusuable state
machine approach, surely you can do one better.
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:21 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

--
Regards,
Bruce McGee
Glooscap Software
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 12:55 PM   in response to: Bruce McGee in response to: Bruce McGee
Bruce McGee <bmcgee at glooscap dot com> wrote in news:696840
@forums.embarcadero.com:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

There is no problem with ansi strings... it is trivial, and more
important it reflects the protocol (which is important in the real
McCoy)

Pretty much as follows (without all error checking or optimisation),
assuming we
have ansi strings, and ansi string libraries. I've taken out all my
libraries that do much of this in one place for re-use, and it should
all be raw RTL.

input
Data:ansistring;
Check:integer;
output
Success:boolean;
ResultInfo,SenderInfo,OutData1,OutData2:string;
var
P1,P2,P3,P4:byte;
V:TArray<ansistring>;
begin
P1:= pos(<1>,Data);
P2:= pos(<2>,Data);
P3:= pos(<3>,Data);
P4:= pos(<4>,Data);
if (P1=1) and (P4=length(Data)) and (P2<>0) then
begin
SenderInfo:=copy(Data,P1+1,P2-P1-1); // To UNICODE
Success:=P3<>0;
if Sucess then // error result
begin
ResultInfo:=copy(Data,P3+1,P4-1);
Data:=copy(Data,P2+1,P3-P2-1);
V:=OutData1,Split([',']);
if (length(V)=3) and (V[2].ToUpper='Y')
and ValidateChechsum(Data,Check) then
begin
Outdata1:=V[0]; // To UNICODE
OutData2:=V[1]; // To UNICODE
end
else
Error(missing)
end
else
begin
V:= copy(Data,P3+1,P4-1),Split([',']);
if (length(V)=2) and (V[2].ToUpper[1] in ['E','N']) then
ResultInfo:= V[1] // To UNICODE
else
Error(Missing)
end;
end
else
Error(missing)
end
Uwe Raabe

Posts: 180
Registered: 10/20/00
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 2:47 AM   in response to: Christopher Burke in response to: Christopher Burke
Am 13.10.2014 um 21:55 schrieb Christopher Burke:
Pretty much as follows (without all error checking or optimisation),
assuming we
have ansi strings, and ansi string libraries. I've taken out all my
libraries that do much of this in one place for re-use, and it should
all be raw RTL.

Although your code doesn't match the challenge and also has some flaws,
I used it as a template to make a solution. Feel free to adapt it to
reality.

program Project41;

{$APPTYPE CONSOLE}
{$R *.res}

uses
System.SysUtils,
System.Types,
System.Generics.Collections,
System.StrUtils;

type
TBytesHelper = record helper for TBytes
function Pos(AByte: Byte): Integer;
public
function Extract(StartIndex, Count: Integer): TBytes;
function GetString(StartIndex, Count: Integer): string; overload;
function GetString: string; overload;
end;

function TBytesHelper.Extract(StartIndex, Count: Integer): TBytes;
begin
Result := Copy(Self, StartIndex, Count);
end;

function TBytesHelper.GetString(StartIndex, Count: Integer): string;
begin
Result := TEncoding.ASCII.GetString(Self, StartIndex, Count);
end;

function TBytesHelper.GetString: string;
begin
Result := TEncoding.ASCII.GetString(Self);
end;

function TBytesHelper.Pos(AByte: Byte): Integer;
var
I: Integer;
begin
Result := -1;
for I := Low(Self) to High(Self) do begin
if Self[I] = AByte then
Exit(I);
end;
end;

function ValidateChechsum(Data: TBytes; Check: Integer): Boolean;
begin
Result := true;
end;

function Extract(Data: TBytes; Check: Integer): string;
var
Outdata1: string;
OutData2: string;
P1, P2, P3, P4: Integer;
ResultInfo: string;
SenderInfo: string;
Success: Boolean;
tmp: TBytes;
V: TArray<string>;
begin
result := 'Error';
P1 := Data.Pos(1);
P2 := Data.Pos(2);
P3 := Data.Pos(3);
P4 := Data.Pos(4);

if (P1 = Low(Data)) and (P4 = High(Data)) and (P2 > P1) then begin
SenderInfo := Data.GetString(P1 + 1, P2 - P1 - 1);
Success := P3 > P1;
if Success then begin
ResultInfo := Data.GetString(P3 + 1, P4 - P3 - 1);
tmp := Data.Extract(P2 + 1, P3 - P2 - 1);
V := tmp.GetString.Split([',']);
if (length(V) = 3) and (V[2].ToUpper = 'Y') and
ValidateChechsum(tmp, Check) then begin
Outdata1 := V[0];
OutData2 := V[1];
result := Format('VALID: %s, %s, %s, %s', [SenderInfo,
Outdata1, Outdata2, resultinfo]);
end
else begin
Abort;
end;
end
else begin
V := Data.GetString(P2 + 1, P4 - P2 - 1).Split([',']);
if (length(V) = 2) and MatchText(V[1].Substring(0, 1), ['E',
'N']) then begin
ResultInfo := V[0];
result := Format('ERROR: %s, %s', [SenderInfo, resultinfo]);
end
else begin
Abort;
end;
end;
end
else begin
Abort;
end;
end;

var
cA: TBytes;
cB: TBytes;
begin
try
cA := [1] + TEncoding.ASCII.GetBytes('sender info') +
[2] + TEncoding.ASCII.GetBytes('data,data,Y') +
[3] + TEncoding.ASCII.GetBytes('result info') +
[4];
cB := [1] + TEncoding.ASCII.GetBytes('sender info') +
[2] + TEncoding.ASCII.GetBytes('result info,N') +
[4];
Writeln(Extract(cA, 0));
Writeln(Extract(cB, 0));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.

david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 7:56 AM   in response to: Christopher Burke in response to: Christopher Burke
Are the following mods to your example problematic? (About 6 or so lines.
Of course, not compiled nor tested, and based on 2006/2007 knowledge.)
Incorrect?
(The assumption is that your input of ansistring can be an input of
array[0..127] of byte.
You have stated it had to be done without AnsiStrings, so I assume to meet
that requirement you are able to provide the input also without ansistrings.
If that's not possible, why not? And how would you otherwise meet your own
requirement?
)

"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:696884 at forums dot embarcadero dot com...
Bruce McGee <bmcgee at glooscap dot com> wrote in news:696840
@forums.embarcadero.com:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

There is no problem with ansi strings... it is trivial, and more
important it reflects the protocol (which is important in the real
McCoy)

Pretty much as follows (without all error checking or optimisation),
assuming we
have ansi strings, and ansi string libraries. I've taken out all my
libraries that do much of this in one place for re-use, and it should
all be raw RTL.

input

ASCIIData:array [0..127] of byte;
ASCIIDataLen:integer;

Check:integer;
output
Success:boolean;
ResultInfo,SenderInfo,OutData1,OutData2:string;
var
P1,P2,P3,P4:byte;
V:TArray<ansistring>;

i:integer;
Data:string;

begin
for i:= 0 to ASCIIDataLen-1 do string := string + chr(ASCIIData[i]);
P1:= pos(<1>,Data);
P2:= pos(<2>,Data);
P3:= pos(<3>,Data);
P4:= pos(<4>,Data);
if (P1=1) and (P4=length(Data)) and (P2<>0) then
begin
SenderInfo:=copy(Data,P1+1,P2-P1-1); // To UNICODE
Success:=P3<>0;
if Sucess then // error result
begin
ResultInfo:=copy(Data,P3+1,P4-1);
Data:=copy(Data,P2+1,P3-P2-1);
V:=OutData1,Split([',']);
if (length(V)=3) and (V[2].ToUpper='Y')
and ValidateChechsum(Data,Check) then
begin
Outdata1:=V[0]; // To UNICODE
OutData2:=V[1]; // To UNICODE
end
else
Error(missing)
end
else
begin
V:= copy(Data,P3+1,P4-1),Split([',']);
if (length(V)=2) and (V[2].ToUpper[1] in ['E','N']) then
ResultInfo:= V[1] // To UNICODE
else
Error(Missing)
end;
end
else
Error(missing)
end
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 8:23 AM   in response to: david hoke in response to: david hoke
Oops, appears also
V:TArray<ansistring>
should have been changed to
V:Tarray<string> ...

"david hoke" <dhoke.nojunk@east-shore.com> wrote in message
news:697047 at forums dot embarcadero dot com...
Are the following mods to your example problematic? (About 6 or so
lines. Of course, not compiled nor tested, and based on 2006/2007
knowledge.)
Incorrect?
(The assumption is that your input of ansistring can be an input of
array[0..127] of byte.
You have stated it had to be done without AnsiStrings, so I assume to meet
that requirement you are able to provide the input also without
ansistrings.
If that's not possible, why not? And how would you otherwise meet your
own requirement?
)

"Christopher Burke" <newsgroups at craznar dot com> wrote in message
news:696884 at forums dot embarcadero dot com...
Bruce McGee <bmcgee at glooscap dot com> wrote in news:696840
@forums.embarcadero.com:

Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

There is no problem with ansi strings... it is trivial, and more
important it reflects the protocol (which is important in the real
McCoy)

Pretty much as follows (without all error checking or optimisation),
assuming we
have ansi strings, and ansi string libraries. I've taken out all my
libraries that do much of this in one place for re-use, and it should
all be raw RTL.

input

ASCIIData:array [0..127] of byte;
ASCIIDataLen:integer;

Check:integer;
output
Success:boolean;
ResultInfo,SenderInfo,OutData1,OutData2:string;
var
P1,P2,P3,P4:byte;
V:TArray<ansistring>;

i:integer;
Data:string;

begin
for i:= 0 to ASCIIDataLen-1 do string := string + chr(ASCIIData[i]);
P1:= pos(<1>,Data);
P2:= pos(<2>,Data);
P3:= pos(<3>,Data);
P4:= pos(<4>,Data);
if (P1=1) and (P4=length(Data)) and (P2<>0) then
begin
SenderInfo:=copy(Data,P1+1,P2-P1-1); // To UNICODE
Success:=P3<>0;
if Sucess then // error result
begin
ResultInfo:=copy(Data,P3+1,P4-1);
Data:=copy(Data,P2+1,P3-P2-1);
V:=OutData1,Split([',']);
if (length(V)=3) and (V[2].ToUpper='Y')
and ValidateChechsum(Data,Check) then
begin
Outdata1:=V[0]; // To UNICODE
OutData2:=V[1]; // To UNICODE
end
else
Error(missing)
end
else
begin
V:= copy(Data,P3+1,P4-1),Split([',']);
if (length(V)=2) and (V[2].ToUpper[1] in ['E','N']) then
ResultInfo:= V[1] // To UNICODE
else
Error(Missing)
end;
end
else
Error(missing)
end
david hoke

Posts: 616
Registered: 2/9/07
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 8:31 AM   in response to: david hoke in response to: david hoke
FWIW -

"david hoke" <dhoke.nojunk@east-shore.com> wrote in message
news:697047 at forums dot embarcadero dot com...
Are the following mods to your example problematic? (About 6 or so
lines. Of course, not compiled nor tested, and based on 2006/2007
knowledge.)
Incorrect?

While I think the previous mods (including the change to v:TArray<>) should
work, the following may also work, if you want it to be harder.

Note that it was only tried in 2006 environ, but I expect it will work in
unicode environs as well...

=============================================
(*

compile with:
dcc32 -D+ -L+ -V -CC acc.pas

*)

program trychallenge(input,output);
{$apptype console}

const
maxpktsz = 128 ;
initcrcval = 0 ;

type
rawpkt = array[0..maxpktsz-1] of byte ;
pktpiece = record
len : integer ;
data : array [0..maxpktsz-1] of byte ;
end ;

procedure calccrc(var crcval:cardinal;abyte:byte);
begin
crcval := crcval+abyte ; //lazy way out for now.
end;

procedure extractpieces
(var senderinfo:String;
var data1:String;
var data2:String;
var flag:String;
var resultinfo:String;
var ok:boolean;
var errval:integer;
var errloc:integer;
var formno:integer;
const pkt:rawpkt
);
var
i : integer ;
crc1 : cardinal ;
missingtwo : boolean;
begin
i := 0 ;
if((pkt[i] > 4) or (pkt[i]=0)) then begin
errval := 1 ; //invalid beginning of packet
errloc := i ;
ok := false ;
exit ;
end ;
if(pkt[i] <> 1)then begin
errloc := i ;
errval := 2 ; //missing <1> at beginning of packet
ok := false ;
exit ;
end;
inc(i) ;
if(i>=maxpktsz)then begin errval:=99; exit; end;
senderinfo := '' ;
while((pkt[i] <> 2)and(pkt[i]<>3)and(i<maxpktsz))do begin
senderinfo := senderinfo + chr(pkt[i]);
inc(i);
end;
if(i>=maxpktsz)then begin errval:=99; exit; end;
data1 := '' ;
data2 := '' ;
crc1 := initcrcval ;
if(pkt[i] = 2)then begin //process <2> section
formno := 1 ;
missingtwo := false ;
inc(i);
if(i>=maxpktsz)then begin errval:=99; exit; end;
while((pkt[i] > 4) and (pkt[i] <> ord(','))and(i<maxpktsz)) do begin
data1 := data1 + chr(pkt[i]) ;
calccrc(crc1,pkt[i]) ;
inc(i) ;
end;
if(i>=maxpktsz)then begin errval:=99; exit; end;
if(pkt[i]<=4)then begin
errloc := i ;
errval := 3 ; //protocol error
ok := false ;
exit ;
end;
if(pkt[i]=ord(','))then begin calccrc(crc1,pkt[i]);inc(i);end;
if(i>=maxpktsz)then begin errval:=99; exit; end;
while((pkt[i] > 4) and (pkt[i] <> ord(','))and(i<maxpktsz)) do begin
data2 := data2 + chr(pkt[i]) ;
calccrc(crc1,pkt[i]) ;
inc(i) ;
end;
if(i>=maxpktsz)then begin errval:=99; exit; end;
if(pkt[i]<=4)then begin
errloc := i ;
errval := 3 ; //protocol error
ok := false ;
exit ;
end;
if(pkt[i]=ord(','))then begin
calccrc(crc1,pkt[i]);
inc(i);//past comma before FLAG
end
else begin
errloc := i ;
errval := 4 ; //missing flag
ok := false ;
exit ;
end;
//inc(i); //past comma before FLAG
flag := chr(pkt[i]);
if (flag <> 'y') and (flag <> 'Y') and (flag <> 'n') and (flag <> 'N')
and (flag<>'e') and (flag <> 'E') then begin
errloc := i ;
errval := 6 ; //invalid flag value
ok := false ;
exit ;
end;
calccrc(crc1,pkt[i]);
inc(i);
if(i>=maxpktsz)then begin errval:=99; exit; end;
//validate the computed crc - match value to come from ?
//if(crc1 <> expectedcrc)then crcerror;
end
else begin
missingtwo := true ;
formno := 2 ;
end;
if(pkt[i] <> 3)then begin
errloc := i ;
errval := 5 ; //protocol error, <3> expected
ok := false ;
exit ;
end;
inc(i);
if(i>=maxpktsz)then begin errval:=99; exit; end;
//handle <3> section
while((pkt[i] > 4) and (pkt[i] <> ord(','))and(i<maxpktsz)) do begin
resultinfo := resultinfo + chr(pkt[i]);
inc(i);
end;
if(i>=maxpktsz)then begin errval:=99; exit; end;
if(pkt[i]=4) and (missingtwo)then begin
errloc := i ;
errval := 7 ; //protocol error, ',' expected when section <2> missing
ok := false ;
exit ;
end;
if( missingtwo )then begin
if(pkt[i]<>ord(',')) then begin
errloc := i ;
errval := 8 ; //internal error, should not occur
ok := false ;
exit ;
end
else begin
inc(i);//past comma
if(i>=maxpktsz)then begin errval:=99; exit; end;
flag := chr(pkt[i]);
inc(i);
if(i>=maxpktsz)then begin errval:=99; exit; end;
end;
end;
if(pkt[i] <> 4)then begin
errloc := i ;
errval := 9 ; //protocol error, expected <4>
ok := false ;
exit ;
end;

ok:=true;
end;

var
teststr1 : String;
teststr2 : String;
var senderinfo:String;
var data1:String;
var data2:String;
var flag:String;
var resultinfo:String;
var ok:boolean;
var errval,errloc:integer;
formno:integer;
bytepkt : rawpkt;
i : integer ;

begin
writeln('starting...');
teststr1 := #$1+'senderinfo'+#$2+'data1,data2,Y'+#$3'resultinfo'+#$4;

for i := 1 to length(teststr1) do
bytepkt[i-1] := ord(teststr1[i]);

extractpieces(senderinfo,data1,data2,flag,resultinfo,ok,errval,errloc,formno,bytepkt);
if(not ok) then begin
writeln('PROTOCOL ERROR ',errval); //error tells crudely where/why in
source
end
else begin
if(formno=1)then
writeln('VALID:',senderinfo,',',data1,',',data2,',',resultinfo)
else writeln('ERROR: ',senderinfo,',',resultinfo);
end;

teststr2 :=
#$1+'XsenderinfoX'+#$2+'Xdata1X,Ydata2Y,Y'+#$3+'YresultinfoY'+#$4;
for i := 1 to length(teststr2) do
bytepkt[i-1] := ord(teststr2[i]);

extractpieces(senderinfo,data1,data2,flag,resultinfo,ok,errval,errloc,formno,bytepkt);
if(not ok) then begin
writeln('PROTOCOL ERROR ',errval); //error tells crudely where/why in
source
end
else begin
if(formno=1)then
writeln('VALID:',senderinfo,',',data1,',',data2,',',resultinfo)
else writeln('ERROR: ',senderinfo,',',resultinfo);
end;

end.

Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 2:11 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

There is no problem with ansi strings... it is trivial, and more
important it reflects the protocol (which is important in the real
McCoy)

Also apparently trivial without them.

So what's the problem?

--
Regards,
Bruce McGee
Glooscap Software
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:24 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

--
Regards,
Bruce McGee
Glooscap Software
Bruce McGee

Posts: 1,716
Registered: 9/30/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:24 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher Burke wrote:

THE ANSI STRING CHALLENGE

Can you do without ANSI Strings, here is the challenge.

At least you're finally asking the right questions.

I agree with other posts - don't expect others to do all your work for
you. Show how you would solve this hypothetical problem, first.

--
Regards,
Bruce McGee
Glooscap Software
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 5:02 PM   in response to: Christopher Burke in response to: Christopher Burke
Christopher wrote:

You have an an ascii string of up to 128 bytes long, and is of the following
form

Either

A: <1>sender info<2>data,data,FLAG<3>result info<4>
or
B: <1>sender info<3>result info,FLAG<4>

Store the raw bytes into a byte array, such as TBytes.

1. <1> <2> <3> <4> are ascii control characters (SOT,SOH,EOH,EOT for
example - they will always be between 1 and 31 and never 0).

SOH = start of heading = byte $01
SOT = start of text (more commonly known as STX) = byte $02
EOT = end of text (more commonly known as ETX) = byte $03
EOH = no such identifier (maybe you mean end of transmission, more commonly
known as EOT) = byte $04

2. THe block is ASCII data and is a single block of data (embedded in
another packet)..

Simply copy the data to its own byte array and then process as needed. Or,
if the packet itself is stored as a byte array, simply index to where the
ASCII data begins, and don't exceed the index where the ASCII data ends.

3. The data is in one of two formats, that format based upon the value
of FLAG (Y/y or N/n/E/e).

Based on the format shown, you don't need to look at the FLAG field to know
what fields are available. Plus, it is pretty stupid to put a format flag
at the END of the data being formatted. That implies you need to know the
format up front in order to find the flag field. Unless you process the
data backwards.

6. You must validate <2>XXXX<3> by doing a CRC vs a provided value
(from higher level block).

CRCs operate on bytes, not on characters. All the more reason to process
the data as a byte array, converting to String only when needed.

7. sender info : details of the terminal, user and location that sent
the requed.

You must write this using NO ansi strings, nor writing any routines or
code chunks that emulate ansi string functionality. It must be
reusable across multiple cases (up to 10 different external vendor
protocols).

That is not a very fiesible requirement. Every protocol is different, and
would require different processing rules. Unless they contain some semblance
of a common layout for the data, in which case you are coding to the layout,
not the protocol.

Assume you receive an array of bytes 128 bytes long with a number of
bytes used field, or a TBytes etc.

At least you receives the original data with the correct data type to being
with. Processing bytes as strings is easy after that.

That is - you must prove that ansi strings are NOT required to extract
this data, the intent is not to prove that you can write ansi strings
yourself (that is obviously possible - after all Delphi for desktop
has them).

Since your data is pure ASCII, which includes control characters < 31, then
simpliest answer would be to convert the ENTIRE array to a single UnicodeString
and then use normal String routines to parse it, as there is a 1-to-1 conversion
between ASCII and Unicode, by design of the Unicode standard:

{$ZEROBASEDSTRINGS OFF}
procedure Process(const Bytes: TBytes; CRCToValidate: Word);
var
  S, SenderInfo, Data, ResultInfo: String;
  B: TBytes;
  CRCCalculated: Word;
  Idx: Integer;
  IsValid, IsError: Boolean;
begin
  IsValid := False;
  IsError := False;
  S := TEncoding.ASCII.GetString(Bytes);
  if S = '' then raise Exception.Create('Protocol error');
  if (S[1] <> #1) or (S[Length(S)] <> #4) then raise Exception.Create('Protocol 
error');
  S := Copy(S, 2, Length(S)-2);
  Idx := LastDelimiter(#3, S);
  if Idx = 0 then raise Exception.Create('Protocol error');
  ResultInfo := Copy(S, Idx+1, MaxInt);
  SetLength(S, Idx-1);
  Idx := LastDelimiter(#2, S);
  if Idx > 0 then
  begin
    Data := Copy(S, Idx+1, MaxInt);
    B := TEncoding.ASCII.GetBytes(Data);
    CRCCalculated := ...; // perform CRC algorithm (you did not stipulate 
which)...
    if CRCCalculated <> CRCToValidate then raise Exception.Create('CRC failed');
    SetLength(S, Idx-1);
    IsValid := True;
  end else begin
    IsError := True;
  end;
  SenderInfo := S;
  // use SenderInfo, Data, ResultInfo, IsValid, and IsError as needed...
end;

But let's say, for the sake of argument, that you want to process as bytes
and extract only the individual data pieces as UnicodeString, then you can
do something like this instead:

procedure Process(const Bytes: TBytes; CRCToValidate: Word);
var
  SenderInfo, Data, ResultInfo: String;
  CRCCalculated: Word;
  StartIdx, LastIdx, Idx, I: Integer;
  IsValid, IsError: Boolean;
begin
  IsValid := False;
  IsError := False;
  if Length(Bytes) = 0 then raise Exception.Create('Protocol error');
  if (Bytes[Low(Bytes)] <> $1) or (Bytes[High(Bytes)] <> $4) then raise Exception.Create('Protocol 
error');
  StartIdx := Low(Bytes)+1;
  LastIdx := High(Bytes)-1;
  Idx := -1;
  for I := LastIdx downto StartIdx do
  begin
    if Bytes[I] = $3 then
    begin
      Idx := I;
      Break;
    end;
  end;
  if Idx = -1 then raise Exception.Create('Protocol error');
  ResultInfo := TEncoding.ASCII.GetString(Bytes, Idx+1, LastIdx-Idx);
  LastIdx := Idx-1;
  Idx := -1;
  for I := LastIdx downto StartIdx do
  begin
    if Bytes[I] = $2 then
    begin
      Idx := I;
      Break;
    end;
  end;
  if Idx >= 0 then
  begin
    CRCCalculated := ...; // perform CRC algorithm (you did not stipulate 
which) on bytes between Idx+1 and LastIdx...
    if CRCCalculated <> CRCToValidate then raise Exception.Create('CRC failed');
    Data := TEncoding.ASCII.GetString(Bytes, Idx+1, LastIdx-Idx);
    LastIdx := Idx-1;
    IsValid := True;
  end else
    IsError := True;
  SenderInfo := TEncoding.ASCII.GetString(Bytes, StartIdx, LastIdx-StartIdx+1);
  // use SenderInfo, Data, ResultInfo, IsValid, and IsError as needed...
end;


--
Remy Lebeau (TeamB)
Christopher Burke

Posts: 580
Registered: 9/25/99
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2014 9:40 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) <no dot spam at no dot spam dot com> wrote in
news:696979 at forums dot embarcadero dot com:

Simply copy the data to its own byte array and then process as needed.
Or, if the packet itself is stored as a byte array, simply index to
where the ASCII data begins, and don't exceed the index where the
ASCII data ends.

Ok - the entire array is ASCII.


3. The data is in one of two formats, that format based upon the
value of FLAG (Y/y or N/n/E/e).

Based on the format shown, you don't need to look at the FLAG field to
know what fields are available.

Correct, however I have to look at the flag to validate the protocol.

Plus, it is pretty stupid to put a
format flag at the END of the data being formatted.

Yes - there are MANY MANY stupid things in the formats and protocols we
have to support, most of these stupid things come from errors
accumulated over years before documentation AND from the serial ->
tcp/ip conversion process.

Want to hear a doozy, one of our protocols requires the client to listen
to requests from the server, and the server doesn't accept connections.


6. You must validate <2>XXXX<3> by doing a CRC vs a provided value
(from higher level block).

CRCs operate on bytes, not on characters. All the more reason to
process the data as a byte array, converting to String only when
needed.

Correct, the CRC value itself is provided from the outside layer, and
must be calculated from the ASCII data itself.

That is not a very fiesible requirement.

However it is a trivial one compared to the ones we deal with, and ansi
sstrings provide a very efficient and re-usable approach guess why.

Because the incoming data is ascii.

At least you receives the original data with the correct data type to
being with. Processing bytes as strings is easy after that.

The original data is ASCII... that's the fact. How and what we do with
it after that, is up to me/us.

My choice is to get it into UNICODE as soon as practical. That process
requires ansi strings.

Since your data is pure ASCII, which includes control characters < 31,
then simpliest answer would be to convert the ENTIRE array to a single
UnicodeString and then use normal String routines to parse it, as
there is a 1-to-1 conversion between ASCII and Unicode, by design of
the Unicode standard:

Yes, however even that process requires some kind of ansistring
functionality.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 11:25 AM   in response to: Christopher Burke in response to: Christopher Burke
Christopher wrote:

Ok - the entire array is ASCII.

Then I would suggest converting the entire array to a single UnicodeString
via TEncoding.ASCII.GetString() or similar, then parse the UnicodeString
like any other string.

Correct, however I have to look at the flag to validate the protocol.

True, but you can do that after you have extracted the relevant strings from
the packet bytes.

The original data is ASCII... that's the fact.

I get that. But ASCII is just an encoding scheme, it defines CHARACTER values,
not BYTE values. You are receiving BYTES. It just HAPPENS that ASCII values
fit in 7bit, so 1 BYTE can hold 1 ASCII-encoded CHARACTER. So there is nothing
stopping you from converting BYTES to CHARACTERS before processing the CHARACTERS
as needed. That is the part you keep avoiding by claiming to require AnsiString
to process the BYTES. You don't.

My choice is to get it into UNICODE as soon as practical. That process
requires ansi strings.

No, it does not! Proof has been proved to you by several people now. Stop
saying you need AnsiString for conversions. THAT IS NOT REQUIRED! There
are OTHER WAYS provided by Delphi's RTL to accomplish such conversions WITHOUT
ANSISTRING!

Yes, however even that process requires some kind of ansistring
functionality.

NO IT DOES NOT!

--
Remy Lebeau (TeamB)
John Treder

Posts: 349
Registered: 8/2/02
Re: The ANSI String Challenge
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2014 8:19 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (