comp.lang.ada
 help / color / mirror / Atom feed
* Convert a Wide_String (or a Wide_Character) to an Integer.
@ 2015-02-10 21:16 lomoscompany
  2015-02-10 21:38 ` Jeffrey Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: lomoscompany @ 2015-02-10 21:16 UTC (permalink / raw)


Why does it have to be so damn complicated?

I have the following function:

function Get_Lexical_Category (Input : in Wide_String)
    return Lexical_Category_Id is
    -- Retrieves the number representing the lexical category
    -- of the word.

    Number_Index : Integer
                 := Lexical_Category_Position;
    Lexical_Category : Wide_Character
                     := Input(Input'First - 1 + Number_Index);
begin
    -- NEED TO RETURN AN INTEGER CREATED FROM A SINGLE CHARACTER IN A WIDE 
    -- STRING HERE
end Get_Lexical_Category;

How does one convert a Wide_String into a normal String? Or, in my case, a Wide_Character to a Character.

Or is there any version of "Integer'Value" that takes Wide_Strings?


Thanks a lot for any help, this is really frustrating.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-10 21:16 Convert a Wide_String (or a Wide_Character) to an Integer lomoscompany
@ 2015-02-10 21:38 ` Jeffrey Carter
  2015-02-10 21:51 ` Randy Brukardt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2015-02-10 21:38 UTC (permalink / raw)


On 02/10/2015 02:16 PM, lomoscompany@gmail.com wrote:
> Why does it have to be so damn complicated?

It isn't.

> How does one convert a Wide_String into a normal String? Or, in my case, a Wide_Character to a Character.

The package Ada.Characters.Conversions defines functions To_Character, which
convert a [Wide_]Wide_Character to Character. There are also similar To_String
functions. See ARM A.3.4:

http://www.adaic.org/resources/add_content/standards/12rm/html/RM-A-3-4.html

Anyone using Ada should be familiar with the contents of ARM Annex A, which
defines the standard library.



>     -- NEED TO RETURN AN INTEGER CREATED FROM A SINGLE CHARACTER IN A WIDE 
>     -- STRING HERE

To convert a single character to an integer value presumes that the character is
a digit. That can be converted more simply with

Character'Pos (Char) - Character'Pos ('0')

Presuming that the digits are contiguous beginning with '0' for Wide_Character,
this would work with Wide_Character'Pos as well.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-10 21:16 Convert a Wide_String (or a Wide_Character) to an Integer lomoscompany
  2015-02-10 21:38 ` Jeffrey Carter
@ 2015-02-10 21:51 ` Randy Brukardt
  2015-02-10 22:38 ` lomoscompany
  2015-02-13 22:11 ` lomoscompany
  3 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2015-02-10 21:51 UTC (permalink / raw)


<lomoscompany@gmail.com> wrote in message 
news:19fa66d7-91ac-4196-9c8f-c633950b9e39@googlegroups.com...
In addition to Jeff's answers...

...
> Or is there any version of "Integer'Value" that takes Wide_Strings?

Of course there is, right next to the definition of 'Value in the Standard 
(see 3.5).

                     Randy.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-10 21:16 Convert a Wide_String (or a Wide_Character) to an Integer lomoscompany
  2015-02-10 21:38 ` Jeffrey Carter
  2015-02-10 21:51 ` Randy Brukardt
@ 2015-02-10 22:38 ` lomoscompany
  2015-02-11  1:18   ` David Botton
  2015-02-13 22:11 ` lomoscompany
  3 siblings, 1 reply; 9+ messages in thread
From: lomoscompany @ 2015-02-10 22:38 UTC (permalink / raw)


On Tuesday, February 10, 2015 at 1:16:54 PM UTC-8, lomosc...@gmail.com wrote:
> Why does it have to be so damn complicated?
> 
> I have the following function:
> 
> function Get_Lexical_Category (Input : in Wide_String)
>     return Lexical_Category_Id is
>     -- Retrieves the number representing the lexical category
>     -- of the word.
> 
>     Number_Index : Integer
>                  := Lexical_Category_Position;
>     Lexical_Category : Wide_Character
>                      := Input(Input'First - 1 + Number_Index);
> begin
>     -- NEED TO RETURN AN INTEGER CREATED FROM A SINGLE CHARACTER IN A WIDE 
>     -- STRING HERE
> end Get_Lexical_Category;
> 
> How does one convert a Wide_String into a normal String? Or, in my case, a Wide_Character to a Character.
> 
> Or is there any version of "Integer'Value" that takes Wide_Strings?
> 
> 
> Thanks a lot for any help, this is really frustrating.

Thanks, both of you. I guess I'll have to study the reference manual.. I have no idea how I'm going to remember all of that, but I'll try.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-10 22:38 ` lomoscompany
@ 2015-02-11  1:18   ` David Botton
  2015-02-11 21:59     ` lomoscompany
  0 siblings, 1 reply; 9+ messages in thread
From: David Botton @ 2015-02-11  1:18 UTC (permalink / raw)


> Thanks, both of you. I guess I'll have to study the reference manual.. I have no idea how I'm going to remember all of that, but I'll try.

You don't have to remember it all, just know where to look when you need. Don't be discouraged and with Ada it is all exceptionally well documented and always readable. You can't say that about most languages.

David Botton

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-11  1:18   ` David Botton
@ 2015-02-11 21:59     ` lomoscompany
  2015-02-11 22:05       ` David Botton
  0 siblings, 1 reply; 9+ messages in thread
From: lomoscompany @ 2015-02-11 21:59 UTC (permalink / raw)


On Tuesday, February 10, 2015 at 5:18:49 PM UTC-8, David Botton wrote:
> > Thanks, both of you. I guess I'll have to study the reference manual.. I have no idea how I'm going to remember all of that, but I'll try.
> 
> You don't have to remember it all, just know where to look when you need. Don't be discouraged and with Ada it is all exceptionally well documented and always readable. You can't say that about most languages.
> 
> David Botton

I know, it really is a beautiful language. I just don't have any luck trying to search for things in the RM. Google spits out tons of useless information that just leaves me slogging through tens of sites containing nothing of interest.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-11 21:59     ` lomoscompany
@ 2015-02-11 22:05       ` David Botton
  2015-02-12 20:09         ` Randy Brukardt
  0 siblings, 1 reply; 9+ messages in thread
From: David Botton @ 2015-02-11 22:05 UTC (permalink / raw)


> I know, it really is a beautiful language. I just don't have any luck trying to search for things in the RM. Google spits out tons of useless information that just leaves me slogging through tens of sites containing nothing of interest.

1) Download the pdf - http://www.ada-auth.org/standards/ada12.html

2) Use the magic of google searching like this:

site:www.ada-auth.org/standards/12rm/html _______

where _____ is your query

3) Use the search feature at ada-auth.org's html version:

http://www.ada-auth.org/standards/12rm/html/RM-SRCH.html


Enjoy!
David Botton

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-11 22:05       ` David Botton
@ 2015-02-12 20:09         ` Randy Brukardt
  0 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2015-02-12 20:09 UTC (permalink / raw)


"David Botton" <david@botton.com> wrote in message 
news:f3768323-7e95-4bc5-9284-e2cfa5295a93@googlegroups.com...
>> I know, it really is a beautiful language. I just don't have any luck 
>> trying to search for things in the RM. Google spits out tons of useless 
>> information that just leaves me slogging through tens of sites containing 
>> nothing of interest.
>
> 1) Download the pdf - http://www.ada-auth.org/standards/ada12.html
>
> 2) Use the magic of google searching like this:
>
> site:www.ada-auth.org/standards/12rm/html _______
>
> where _____ is your query
>
> 3) Use the search feature at ada-auth.org's html version:
>
> http://www.ada-auth.org/standards/12rm/html/RM-SRCH.html

Not to mention

4) Use the Ada-wide search engine, which searches 80,000+ pages of Ada 
content:

http://www.adaic.org/ada-resources/ada-on-the-web/

I hope to get the latter two moved to a modern server sometime this year. 
The current server is a bit underpowered (the new server has 32 times the 
computing power!) and that can make the search engine sluggish. But if you 
have patience with it, it will return your results.

                                  Randy.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Convert a Wide_String (or a Wide_Character) to an Integer.
  2015-02-10 21:16 Convert a Wide_String (or a Wide_Character) to an Integer lomoscompany
                   ` (2 preceding siblings ...)
  2015-02-10 22:38 ` lomoscompany
@ 2015-02-13 22:11 ` lomoscompany
  3 siblings, 0 replies; 9+ messages in thread
From: lomoscompany @ 2015-02-13 22:11 UTC (permalink / raw)


Awesome. Thanks to all of you, I have lots to study. I'll probably end up making some cheat-sheets to aid me. The searching engine looks like a powerful tool. I'll have to play around with it, so that it doesn't return unit-tests, but I can already see the potential!

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-02-13 22:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10 21:16 Convert a Wide_String (or a Wide_Character) to an Integer lomoscompany
2015-02-10 21:38 ` Jeffrey Carter
2015-02-10 21:51 ` Randy Brukardt
2015-02-10 22:38 ` lomoscompany
2015-02-11  1:18   ` David Botton
2015-02-11 21:59     ` lomoscompany
2015-02-11 22:05       ` David Botton
2015-02-12 20:09         ` Randy Brukardt
2015-02-13 22:11 ` lomoscompany

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox