Re: charIndex property

2023-07-31 Thread Bob Sneidar via use-livecode
Are you using Thunderbird for an email client? Or are you copying from the 
forum? This was talked about years ago. For some reason different apps format 
clipboard text differently, and this is an artifact of one of those apps. That 
is why I paste, then re-copy code in a text editor like TextEdit or Sublime 
Text. If I don’t, then the lines are double spaced and it looks like crap and 
is hard to read.

:-)

Bob S


On Jul 31, 2023, at 9:08 AM, Paul Dupuis via use-livecode 
 wrote:

I have no idea why pasting placed *'s all over the place!

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-31 Thread Bob Sneidar via use-livecode
On Jul 31, 2023, at 8:54 AM, Paul Dupuis via use-livecode 
 wrote:

Bob,

Here is a version of Mark's method, for trueWords, sentences, and paragraphs, 
with the added parameter of pDirection to get the char index of the start of 
the chunk or the end of the chunk containing the character position pChunkIndex.

Thanks, but whatever email app you sent from borked the code, putting asterisks 
before and after every keyword and running other words together. I always 
paste/copy my code in a generic text editor before sending to the list.

At any rate, I cleaned it up and here is the code. Not sure why you made it a 
private function but I removed the keyword PRIVATE so it could be used anywhere.

Thanks Mark for this effort. I think it should become part of the Master 
Library.

Bob S

function  rwCharIndex pText, pChunkType, pChunkIndex, pDirection
   -- pText is the full text
   -- pChunkType is once of: words|sentences|paragraphs
   -- pChunkIndex is the integer index in the indicated units. ie. "word",7 is 
the 7th word
   -- pDirection is one of: first|last meaning either the 1st character of the 
chunk or the last character
   -- error checking, empty is returned if an error occurs with the parameters
   if  pText is empty then return empty
   if  pChunkType is not among the items of "words,sentences,paragraphs" then 
return empty
   if  pChunkIndex is not an integer then return empty
   if  pDirection is not among the items of "first,last" then return empty
   local tL
   switch  pChunkType
  case  "words"
 switch  pDirection
case  "first"
   put null into trueWord pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of chars in pText + 1)
   break
case  "last"
   put length(trueWord pChunkIndex of pText) into tL
   put null into trueWord pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of characters in pText + tL)
   break
 end   switch
 break
  case  "sentences"
 switch  pDirection
case  "first"
   put null into sentence pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of chars in pText + 1)
   break
case  "last"
   put length(sentence pChunkIndex of pText) into tL
   put null into sentence pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of characters in pText + tL)
   break
 end   switch
 break
  case  "paragraphs"
 switch  pDirection
case  "first"
   put null into paragraph pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of chars in pText + 1)
   break
case  "last"
   put length(paragraph pChunkIndex of pText) into tL
   put null into paragraph pChunkIndex to-1 of pText
   put codeunitOffset(null,pText) into N
   delete codeunit N to-1 of pText
   return (the number of characters in pText + tL)
   break
 end   switch
 break
   end   switch
end rwCharIndex
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-31 Thread Paul Dupuis via use-livecode

I have no idea why pasting placed *'s all over the place!

On 7/31/2023 11:54 AM, Paul Dupuis via use-livecode wrote:

Bob,

Here is a version of Mark's method, for trueWords, sentences, and 
paragraphs, with the added parameter of pDirection to get the char 
index of the start of the chunk or the end of the chunk containing the 
character position pChunkIndex.


*private**function* rwCharIndex pText, pChunkType, pChunkIndex, 
pDirection


*-- pText is the full text*

*-- pChunkType is once of: words|sentences|paragraphs*

*-- pChunkIndex is the integer index in the indicated units. ie. 
"word",7 is the 7th word*


*-- pDirection is one of: first|last meaning either the 1st character 
of the chunk or the last character*


*-- error checking, emty is returned if an error occurs with the 
parameters*


*if* pText isempty*then* *return*empty

*if* pChunkType isnotamongtheitemsof"words,sentences,paragraphs"*then* 
*return*empty


*if* pChunkIndex isnotaninteger*then* *return*empty

*if* pDirection isnotamongtheitemsof"first,last"*then* *return*empty

*local*tL

*switch* pChunkType

*case* "words"

*switch* pDirection

*case* "first"

*put*nullintotrueWordpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(trueWordpChunkIndex ofpText) intotL

*put*nullintotrueWordpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*case* "sentences"

*switch* pDirection

*case* "first"

*put*nullintosentencepChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(sentencepChunkIndex ofpText) intotL

*put*nullintosentencepChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*case* "paragraphs"

*switch* pDirection

*case* "first"

*put*nullintoparagraphpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(paragraphpChunkIndex ofpText) intotL

*put*nullintoparagraphpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*end* *switch*

*end*rwCharIndex




On 7/31/2023 11:44 AM, Bob Sneidar via use-livecode wrote:
I replaced the code in the original function with this code and it 
won’t compile.


Do you mind posting the full working function again?

Bob S


On Jul 27, 2023, at 2:06 PM, Mark Waddingham via use-livecode 
 wrote:


Oh those pesky chunks which don’t ‘cover’ the target string (which 
is actually all of them except codeunit/point/char come to think of 
it). I should have run through a few more examples in my head before 
posting….


Alternative attempt:

Put null into word N to -1 of S
Delete codeunit (codeunitoffset(null, S) to -1 of S
Return the number of chars in S + 1

The problem before was the chars which do not form part of the last 
chunk and remain after deletion.


The above puts in a sentinel char which can be searched for to find 
where the requested chunk started.


Second time lucky? ;)

Mark.

Sent from my iPhone

On 27 Jul 2023, at 21:23, Paul Dupuis via use-livecode 
 wrote:


On 7/27/2023 4:31 AM, Mark Waddingham via use-livecode wrote:

On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
If I have some text in a field, I can use the "charIndex" 
property (see Dictionary) to obtain teh character position of the 
first character of a chunk.


Does anyone know of a clever way to do the equivalent of the 
charIndex for an arbitrary chunk expression for a 
container/variable (i.e. not an actual field object)?

This should work I think:

   function charIndexOfWord pWordIndex, pTarget
  delete word pWordIndex to -1 of pTarget
  return the number of characters in pTarget + 1
   end charIndexOfWord

Deletion of chunks works from the first char that makes up the 
computed range, so you are left with all the characters which sit 
before it.


The index of the character immediately before the start of the 
specified word is the just the number of characters which sit 
before it; and so the index of the first char of the specified 
word (which is what charIndex gives you in a field) is that +1.


The above should work for both +ve and -ve indices, and the 
obvious changes will make it work for other string chunks (i.e. 
change 'Word' for ).



Mark,

Thank you very much. This was a brilliant approach and I should 
have thought of it myself. However, it i

Re: charIndex property

2023-07-31 Thread Paul Dupuis via use-livecode

Bob,

Here is a version of Mark's method, for trueWords, sentences, and 
paragraphs, with the added parameter of pDirection to get the char index 
of the start of the chunk or the end of the chunk containing the 
character position pChunkIndex.


*private**function* rwCharIndex pText, pChunkType, pChunkIndex, pDirection

*-- pText is the full text*

*-- pChunkType is once of: words|sentences|paragraphs*

*-- pChunkIndex is the integer index in the indicated units. ie. 
"word",7 is the 7th word*


*-- pDirection is one of: first|last meaning either the 1st character of 
the chunk or the last character*


*-- error checking, emty is returned if an error occurs with the parameters*

*if* pText isempty*then* *return*empty

*if* pChunkType isnotamongtheitemsof"words,sentences,paragraphs"*then* 
*return*empty


*if* pChunkIndex isnotaninteger*then* *return*empty

*if* pDirection isnotamongtheitemsof"first,last"*then* *return*empty

*local*tL

*switch* pChunkType

*case* "words"

*switch* pDirection

*case* "first"

*put*nullintotrueWordpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(trueWordpChunkIndex ofpText) intotL

*put*nullintotrueWordpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*case* "sentences"

*switch* pDirection

*case* "first"

*put*nullintosentencepChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(sentencepChunkIndex ofpText) intotL

*put*nullintosentencepChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*case* "paragraphs"

*switch* pDirection

*case* "first"

*put*nullintoparagraphpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharsinpText + 1)

*break*

*case* "last"

*put*length(paragraphpChunkIndex ofpText) intotL

*put*nullintoparagraphpChunkIndex to-1 ofpText

*put*codeunitOffset(null,pText) intoN

*delete*codeunitN to-1 ofpText

*return*(thenumberofcharactersinpText + tL)

*break*

*end* *switch*

*break*

*end* *switch*

*end*rwCharIndex




On 7/31/2023 11:44 AM, Bob Sneidar via use-livecode wrote:

I replaced the code in the original function with this code and it won’t 
compile.

Do you mind posting the full working function again?

Bob S



On Jul 27, 2023, at 2:06 PM, Mark Waddingham via use-livecode 
 wrote:

Oh those pesky chunks which don’t ‘cover’ the target string (which is actually 
all of them except codeunit/point/char come to think of it). I should have run 
through a few more examples in my head before posting….

Alternative attempt:

Put null into word N to -1 of S
Delete codeunit (codeunitoffset(null, S) to -1 of S
Return the number of chars in S + 1

The problem before was the chars which do not form part of the last chunk and 
remain after deletion.

The above puts in a sentinel char which can be searched for to find where the 
requested chunk started.

Second time lucky? ;)

Mark.

Sent from my iPhone


On 27 Jul 2023, at 21:23, Paul Dupuis via use-livecode 
 wrote:

On 7/27/2023 4:31 AM, Mark Waddingham via use-livecode wrote:

On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
If I have some text in a field, I can use the "charIndex" property (see 
Dictionary) to obtain teh character position of the first character of a chunk.

Does anyone know of a clever way to do the equivalent of the charIndex for an 
arbitrary chunk expression for a container/variable (i.e. not an actual field 
object)?

This should work I think:

   function charIndexOfWord pWordIndex, pTarget
  delete word pWordIndex to -1 of pTarget
  return the number of characters in pTarget + 1
   end charIndexOfWord

Deletion of chunks works from the first char that makes up the computed range, 
so you are left with all the characters which sit before it.

The index of the character immediately before the start of the specified word 
is the just the number of characters which sit before it; and so the index of 
the first char of the specified word (which is what charIndex gives you in a 
field) is that +1.

The above should work for both +ve and -ve indices, and the obvious changes will make 
it work for other string chunks (i.e. change 'Word' for ).


Mark,

Thank you very much. This was a brilliant approach and I should have thought of 
it myself. However, it is not quite an accurate substitute for the charIndex 
property of a field. The following example illustrates the issue:

pTarget is [The qui

Re: charIndex property

2023-07-31 Thread Bob Sneidar via use-livecode
I replaced the code in the original function with this code and it won’t 
compile. 

Do you mind posting the full working function again? 

Bob S


> On Jul 27, 2023, at 2:06 PM, Mark Waddingham via use-livecode 
>  wrote:
> 
> Oh those pesky chunks which don’t ‘cover’ the target string (which is 
> actually all of them except codeunit/point/char come to think of it). I 
> should have run through a few more examples in my head before posting….
> 
> Alternative attempt:
> 
> Put null into word N to -1 of S
> Delete codeunit (codeunitoffset(null, S) to -1 of S
> Return the number of chars in S + 1
> 
> The problem before was the chars which do not form part of the last chunk and 
> remain after deletion.
> 
> The above puts in a sentinel char which can be searched for to find where the 
> requested chunk started.
> 
> Second time lucky? ;)
> 
> Mark.
> 
> Sent from my iPhone
> 
>> On 27 Jul 2023, at 21:23, Paul Dupuis via use-livecode 
>>  wrote:
>> 
>> On 7/27/2023 4:31 AM, Mark Waddingham via use-livecode wrote:
>>>> On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
>>>> If I have some text in a field, I can use the "charIndex" property (see 
>>>> Dictionary) to obtain teh character position of the first character of a 
>>>> chunk.
>>>> 
>>>> Does anyone know of a clever way to do the equivalent of the charIndex for 
>>>> an arbitrary chunk expression for a container/variable (i.e. not an actual 
>>>> field object)?
>>> 
>>> This should work I think:
>>> 
>>>   function charIndexOfWord pWordIndex, pTarget
>>>  delete word pWordIndex to -1 of pTarget
>>>  return the number of characters in pTarget + 1
>>>   end charIndexOfWord
>>> 
>>> Deletion of chunks works from the first char that makes up the computed 
>>> range, so you are left with all the characters which sit before it.
>>> 
>>> The index of the character immediately before the start of the specified 
>>> word is the just the number of characters which sit before it; and so the 
>>> index of the first char of the specified word (which is what charIndex 
>>> gives you in a field) is that +1.
>>> 
>>> The above should work for both +ve and -ve indices, and the obvious changes 
>>> will make it work for other string chunks (i.e. change 'Word' for ).
>>> 
>> 
>> Mark,
>> 
>> Thank you very much. This was a brilliant approach and I should have thought 
>> of it myself. However, it is not quite an accurate substitute for the 
>> charIndex property of a field. The following example illustrates the issue:
>> 
>> pTarget is [The quick brown fox jumps over the lazy dog. The lazy dog was 
>> named "Oz".]
>> pWordIndex is 8 (having been derived from searching for 'lazy', the 8th word)
>> 
>> Using [] to quote strings.
>> delete word 8 to -1 of pTarget -- deletes [lazy] to ["Oz"] but not the 
>> period (.) at the end since it is not considered part of word -1.
>> This leaves pTarget as [The quick brown fox jumps over the .]
>> The number of characters in pTarget + 1 is actually not the position of the 
>> [l] in [lazy], which is character 36, but the [a] in [azy], character 37, 
>> due to the period being left.
>> 
>> There are some similar issues, being off by  or more, with sentences and 
>> paragraphs in longer text.
>> 
>> Thank you very much for chiming in with a good direction to try.
>> 
>> Paul Dupuis
>> Researchware
>> 
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-29 Thread Mark Smith via use-livecode
Love it  

Sent from my iPhone

> On Jul 28, 2023, at 10:36 PM, Bob Sneidar via use-livecode 
>  wrote:
> 
> This is the essence on Livecode! This is why we love it! Shouldn’t we 
> rebrand it? How about Lovecode?? …..
> 
> Never mind. 
> 
> Sent from my iPhone
> 
>>> On Jul 28, 2023, at 04:55, Paul Dupuis via use-livecode 
>>>  wrote:
>>> 
>>> On 7/27/2023 5:06 PM, Mark Waddingham via use-livecode wrote:
>>> Oh those pesky chunks which don’t ‘cover’ the target string (which is 
>>> actually all of them except codeunit/point/char come to think of it). I 
>>> should have run through a few more examples in my head before posting….
>>> 
>>> Alternative attempt:
>>> 
>>> Put null into word N to -1 of S
>>> Delete codeunit (codeunitoffset(null, S) to -1 of S
>>> Return the number of chars in S + 1
>>> 
>>> The problem before was the chars which do not form part of the last chunk 
>>> and remain after deletion.
>>> 
>>> The above puts in a sentinel char which can be searched for to find where 
>>> the requested chunk started.
>>> 
>>> Second time lucky? ;)
>>> 
>>> 
>> 
>> Second time's the charm. That works for all chunk types tested (trueWord, 
>> sentence, paragraph)! Thank you!
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-28 Thread Bob Sneidar via use-livecode
This is the essence on Livecode! This is why we love it! Shouldn’t we rebrand 
it? How about Lovecode?? …..

Never mind. 

Sent from my iPhone

> On Jul 28, 2023, at 04:55, Paul Dupuis via use-livecode 
>  wrote:
> 
> On 7/27/2023 5:06 PM, Mark Waddingham via use-livecode wrote:
>> Oh those pesky chunks which don’t ‘cover’ the target string (which is 
>> actually all of them except codeunit/point/char come to think of it). I 
>> should have run through a few more examples in my head before posting….
>> 
>> Alternative attempt:
>> 
>> Put null into word N to -1 of S
>> Delete codeunit (codeunitoffset(null, S) to -1 of S
>> Return the number of chars in S + 1
>> 
>> The problem before was the chars which do not form part of the last chunk 
>> and remain after deletion.
>> 
>> The above puts in a sentinel char which can be searched for to find where 
>> the requested chunk started.
>> 
>> Second time lucky? ;)
>> 
>> 
> 
> Second time's the charm. That works for all chunk types tested (trueWord, 
> sentence, paragraph)! Thank you!
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-28 Thread Paul Dupuis via use-livecode

On 7/27/2023 5:06 PM, Mark Waddingham via use-livecode wrote:

Oh those pesky chunks which don’t ‘cover’ the target string (which is actually 
all of them except codeunit/point/char come to think of it). I should have run 
through a few more examples in my head before posting….

Alternative attempt:

Put null into word N to -1 of S
Delete codeunit (codeunitoffset(null, S) to -1 of S
Return the number of chars in S + 1

The problem before was the chars which do not form part of the last chunk and 
remain after deletion.

The above puts in a sentinel char which can be searched for to find where the 
requested chunk started.

Second time lucky? ;)




Second time's the charm. That works for all chunk types tested 
(trueWord, sentence, paragraph)! Thank you!


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-27 Thread Mark Waddingham via use-livecode
Oh those pesky chunks which don’t ‘cover’ the target string (which is actually 
all of them except codeunit/point/char come to think of it). I should have run 
through a few more examples in my head before posting….

Alternative attempt:

Put null into word N to -1 of S
Delete codeunit (codeunitoffset(null, S) to -1 of S
Return the number of chars in S + 1

The problem before was the chars which do not form part of the last chunk and 
remain after deletion.

The above puts in a sentinel char which can be searched for to find where the 
requested chunk started.

Second time lucky? ;)

Mark.

Sent from my iPhone

> On 27 Jul 2023, at 21:23, Paul Dupuis via use-livecode 
>  wrote:
> 
> On 7/27/2023 4:31 AM, Mark Waddingham via use-livecode wrote:
>>> On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
>>> If I have some text in a field, I can use the "charIndex" property (see 
>>> Dictionary) to obtain teh character position of the first character of a 
>>> chunk.
>>> 
>>> Does anyone know of a clever way to do the equivalent of the charIndex for 
>>> an arbitrary chunk expression for a container/variable (i.e. not an actual 
>>> field object)?
>> 
>> This should work I think:
>> 
>>function charIndexOfWord pWordIndex, pTarget
>>   delete word pWordIndex to -1 of pTarget
>>   return the number of characters in pTarget + 1
>>end charIndexOfWord
>> 
>> Deletion of chunks works from the first char that makes up the computed 
>> range, so you are left with all the characters which sit before it.
>> 
>> The index of the character immediately before the start of the specified 
>> word is the just the number of characters which sit before it; and so the 
>> index of the first char of the specified word (which is what charIndex gives 
>> you in a field) is that +1.
>> 
>> The above should work for both +ve and -ve indices, and the obvious changes 
>> will make it work for other string chunks (i.e. change 'Word' for ).
>> 
> 
> Mark,
> 
> Thank you very much. This was a brilliant approach and I should have thought 
> of it myself. However, it is not quite an accurate substitute for the 
> charIndex property of a field. The following example illustrates the issue:
> 
> pTarget is [The quick brown fox jumps over the lazy dog. The lazy dog was 
> named "Oz".]
> pWordIndex is 8 (having been derived from searching for 'lazy', the 8th word)
> 
> Using [] to quote strings.
> delete word 8 to -1 of pTarget -- deletes [lazy] to ["Oz"] but not the period 
> (.) at the end since it is not considered part of word -1.
> This leaves pTarget as [The quick brown fox jumps over the .]
> The number of characters in pTarget + 1 is actually not the position of the 
> [l] in [lazy], which is character 36, but the [a] in [azy], character 37, due 
> to the period being left.
> 
> There are some similar issues, being off by  or more, with sentences and 
> paragraphs in longer text.
> 
> Thank you very much for chiming in with a good direction to try.
> 
> Paul Dupuis
> Researchware
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-27 Thread Paul Dupuis via use-livecode

On 7/27/2023 4:31 AM, Mark Waddingham via use-livecode wrote:

On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
If I have some text in a field, I can use the "charIndex" property 
(see Dictionary) to obtain teh character position of the first 
character of a chunk.


Does anyone know of a clever way to do the equivalent of the 
charIndex for an arbitrary chunk expression for a container/variable 
(i.e. not an actual field object)?


This should work I think:

   function charIndexOfWord pWordIndex, pTarget
  delete word pWordIndex to -1 of pTarget
  return the number of characters in pTarget + 1
   end charIndexOfWord

Deletion of chunks works from the first char that makes up the 
computed range, so you are left with all the characters which sit 
before it.


The index of the character immediately before the start of the 
specified word is the just the number of characters which sit before 
it; and so the index of the first char of the specified word (which is 
what charIndex gives you in a field) is that +1.


The above should work for both +ve and -ve indices, and the obvious 
changes will make it work for other string chunks (i.e. change 'Word' 
for ).




Mark,

Thank you very much. This was a brilliant approach and I should have 
thought of it myself. However, it is not quite an accurate substitute 
for the charIndex property of a field. The following example illustrates 
the issue:


pTarget is [The quick brown fox jumps over the lazy dog. The lazy dog 
was named "Oz".]
pWordIndex is 8 (having been derived from searching for 'lazy', the 8th 
word)


Using [] to quote strings.
delete word 8 to -1 of pTarget -- deletes [lazy] to ["Oz"] but not the 
period (.) at the end since it is not considered part of word -1.

This leaves pTarget as [The quick brown fox jumps over the .]
The number of characters in pTarget + 1 is actually not the position of 
the [l] in [lazy], which is character 36, but the [a] in [azy], 
character 37, due to the period being left.


There are some similar issues, being off by  or more, with sentences and 
paragraphs in longer text.


Thank you very much for chiming in with a good direction to try.

Paul Dupuis
Researchware


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-27 Thread Mark Waddingham via use-livecode

On 2023-07-26 18:02, Paul Dupuis via use-livecode wrote:
If I have some text in a field, I can use the "charIndex" property (see 
Dictionary) to obtain teh character position of the first character of 
a chunk.


Does anyone know of a clever way to do the equivalent of the charIndex 
for an arbitrary chunk expression for a container/variable (i.e. not an 
actual field object)?


This should work I think:

   function charIndexOfWord pWordIndex, pTarget
  delete word pWordIndex to -1 of pTarget
  return the number of characters in pTarget + 1
   end charIndexOfWord

Deletion of chunks works from the first char that makes up the computed 
range, so you are left with all the characters which sit before it.


The index of the character immediately before the start of the specified 
word is the just the number of characters which sit before it; and so 
the index of the first char of the specified word (which is what 
charIndex gives you in a field) is that +1.


The above should work for both +ve and -ve indices, and the obvious 
changes will make it work for other string chunks (i.e. change 'Word' 
for ).


Hope this helps!

Warmest Regards,

Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Build Amazing Things

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-26 Thread Paul Dupuis via use-livecode

On 7/26/2023 8:00 PM, Mike Kerner via use-livecode wrote:

actually, i have a couple of questions, which are maybe suggestions,
but are actually questions, because maybe someone else will be curious
enough to try to solve them
* did you check the oss source to see if the function is available?
No. I have little detailed understanding of the open source Livecode 
code repository. My minimal understanding is that the engine source is 
mostly C++ and my knowledge of C is 30 years out of date. It would be a 
bit challenging for me to try to tease out the algorithm charIndex 
actually uses. An excellent question and idea though! Kudos!

* have you messed with using regex to get around the issue?


My regex is a bit better, although I would not consider myself a regex 
expert. I had not though of exploring regex for this. I might give that 
a try, but if there is a regex expert who sees this that is willing to 
weigh on on how you might do this - even just a pointer in the right 
direction - that would be helpful. Another great question/idea. Thanks!



charIndex is actually really powerful, if tied to a field object. You 
can do thing like "the charIndex of the last character of word 11 to 18 
of field X" and it return the character position of the last character 
of the last word in the chunk. Of course, if that is what you want, "the 
charIndex of char -1 of word 18 of field X" is shorter and does the same 
thing. Complex expressions like: the charIndex of word 8 of sentence 3 
of paragraph 5 of field X work as expected.


Gosh, I really *love* Livecode Script's chunk expressions! They make 
complex text manipulation task so easy!


-- Paul

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-26 Thread Mike Kerner via use-livecode
actually, i have a couple of questions, which are maybe suggestions,
but are actually questions, because maybe someone else will be curious
enough to try to solve them
* did you check the oss source to see if the function is available?
* have you messed with using regex to get around the issue?

On Wed, Jul 26, 2023 at 3:48 PM Paul Dupuis via use-livecode
 wrote:
>
> On 7/26/2023 1:13 PM, Bob Sneidar via use-livecode wrote:
> > OIC what that does. I suggest having a hidden field, setting the text of 
> > that field to your variable, then operating on that field.
> >
> > Bob S
>
> That is what I am currently doing. And I have a hidden field, hidden
> image, hidden player - all for purposes of various operations that you
> can do on real objects that the templateField, templateImage, and
> templatePlayer don't do (although there are some things done very nicely
> with the templates, such as set the rtfText of the templateField to
> ; get the text of the templateField -- for conversion from RTF
> to text (or text to htmlText or htmlText to text or ...)
>
> For reasons past that are not worth bring up in this email list, I have
> a slight aversion to hidden objects and prefer to work with the
> templateObjects or variables when i can.
>
> So, that is the very specific question of this post: Does anyone have a
> clever trick to do the equivalent of charIndex on a variable of text?
>
> I guess the allowed answers are "No" (no post is necessary), Yes (but I
> won't share it) (also no post necessary), Yes, and here it is (thank
> you), or perhaps a 4th, I don't understand the question, please clarify
> (which I would be happy to do if someone thinks they have a clever
> solution and just needs a bit more info)
>
> Paul
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-26 Thread Paul Dupuis via use-livecode

On 7/26/2023 1:13 PM, Bob Sneidar via use-livecode wrote:

OIC what that does. I suggest having a hidden field, setting the text of that 
field to your variable, then operating on that field.

Bob S


That is what I am currently doing. And I have a hidden field, hidden 
image, hidden player - all for purposes of various operations that you 
can do on real objects that the templateField, templateImage, and 
templatePlayer don't do (although there are some things done very nicely 
with the templates, such as set the rtfText of the templateField to 
; get the text of the templateField -- for conversion from RTF 
to text (or text to htmlText or htmlText to text or ...)


For reasons past that are not worth bring up in this email list, I have 
a slight aversion to hidden objects and prefer to work with the 
templateObjects or variables when i can.


So, that is the very specific question of this post: Does anyone have a 
clever trick to do the equivalent of charIndex on a variable of text?


I guess the allowed answers are "No" (no post is necessary), Yes (but I 
won't share it) (also no post necessary), Yes, and here it is (thank 
you), or perhaps a 4th, I don't understand the question, please clarify 
(which I would be happy to do if someone thinks they have a clever 
solution and just needs a bit more info)


Paul


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-26 Thread Bob Sneidar via use-livecode
OIC what that does. I suggest having a hidden field, setting the text of that 
field to your variable, then operating on that field. 

Bob S


> On Jul 26, 2023, at 10:06 AM, Bob Sneidar via use-livecode 
>  wrote:
> 
> Offset?
> 
> Bob S
> 
> 
>> On Jul 26, 2023, at 10:02 AM, Paul Dupuis via use-livecode 
>>  wrote:
>> 
>> If I have some text in a field, I can use the "charIndex" property (see 
>> Dictionary) to obtain teh character position of the first character of a 
>> chunk.
>> 
>> For example, if the field contains:
>> 
>> The quick brown fox jumps over the lazy dog. The lazy dog was named "Oz".
>> 
>> The lazy dog was a great dog.
>> 
>> Then there are 3 instances of  "lazy dog"
>> 
>> trueWord 8 to 9 of the field,  11 to 12, and 17 to 18
>> 
>> You can also determine that first instance "lazy dog" is in sentence 1 to 1 
>> (or just sentence 1) of the field, the 2nd is in sentence 2, and the 3rd in 
>> sentence 3
>> 
>> And you can determine that the first 2 instances are in paragraph 1 and the 
>> 3rd instance of "lazy dog" is in paragraph 2 (using the trueWord, sentence, 
>> and paragraph chunk types)
>> 
>> charIndex lets me determine the start of a sentence or paragraph, such as:
>> 
>> the charIndex of sentence 1 to 1 of fld X --> 1 and the charIndex of 
>> sentence 2 of fld X --> 46 and the charIndex of sentence 3 of fld "X" --> 75
>> 
>> the charIndex of paragraph 1 of fld X --> 1 and the charIndex of paragraph 2 
>> of fld X --> 75
>> 
>> My question is, charIndex appear to ONLY work on an actual field object 
>> (visible or invisible). You get execution errors if you try say:
>> 
>> put the charIndex of word 8 of the text of the templateField
>> 
>> put the charIndex of word 8 of the templateField
>> 
>> put the charIndex of word 8 of tVar
>> 
>> Does anyone know of a clever way to do the equivalent of the charIndex for 
>> an arbitrary chunk expression for a container/variable (i.e. not an actual 
>> field object)?
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: charIndex property

2023-07-26 Thread Bob Sneidar via use-livecode
Offset?

Bob S


> On Jul 26, 2023, at 10:02 AM, Paul Dupuis via use-livecode 
>  wrote:
> 
> If I have some text in a field, I can use the "charIndex" property (see 
> Dictionary) to obtain teh character position of the first character of a 
> chunk.
> 
> For example, if the field contains:
> 
> The quick brown fox jumps over the lazy dog. The lazy dog was named "Oz".
> 
> The lazy dog was a great dog.
> 
> Then there are 3 instances of  "lazy dog"
> 
> trueWord 8 to 9 of the field,  11 to 12, and 17 to 18
> 
> You can also determine that first instance "lazy dog" is in sentence 1 to 1 
> (or just sentence 1) of the field, the 2nd is in sentence 2, and the 3rd in 
> sentence 3
> 
> And you can determine that the first 2 instances are in paragraph 1 and the 
> 3rd instance of "lazy dog" is in paragraph 2 (using the trueWord, sentence, 
> and paragraph chunk types)
> 
> charIndex lets me determine the start of a sentence or paragraph, such as:
> 
> the charIndex of sentence 1 to 1 of fld X --> 1 and the charIndex of sentence 
> 2 of fld X --> 46 and the charIndex of sentence 3 of fld "X" --> 75
> 
> the charIndex of paragraph 1 of fld X --> 1 and the charIndex of paragraph 2 
> of fld X --> 75
> 
> My question is, charIndex appear to ONLY work on an actual field object 
> (visible or invisible). You get execution errors if you try say:
> 
> put the charIndex of word 8 of the text of the templateField
> 
> put the charIndex of word 8 of the templateField
> 
> put the charIndex of word 8 of tVar
> 
> Does anyone know of a clever way to do the equivalent of the charIndex for an 
> arbitrary chunk expression for a container/variable (i.e. not an actual field 
> object)?
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


charIndex property

2023-07-26 Thread Paul Dupuis via use-livecode
If I have some text in a field, I can use the "charIndex" property (see 
Dictionary) to obtain teh character position of the first character of a 
chunk.


For example, if the field contains:

The quick brown fox jumps over the lazy dog. The lazy dog was named "Oz".

The lazy dog was a great dog.

Then there are 3 instances of  "lazy dog"

trueWord 8 to 9 of the field,  11 to 12, and 17 to 18

You can also determine that first instance "lazy dog" is in sentence 1 
to 1 (or just sentence 1) of the field, the 2nd is in sentence 2, and 
the 3rd in sentence 3


And you can determine that the first 2 instances are in paragraph 1 and 
the 3rd instance of "lazy dog" is in paragraph 2 (using the trueWord, 
sentence, and paragraph chunk types)


charIndex lets me determine the start of a sentence or paragraph, such as:

the charIndex of sentence 1 to 1 of fld X --> 1 and the charIndex of 
sentence 2 of fld X --> 46 and the charIndex of sentence 3 of fld "X" --> 75


the charIndex of paragraph 1 of fld X --> 1 and the charIndex of 
paragraph 2 of fld X --> 75


My question is, charIndex appear to ONLY work on an actual field object 
(visible or invisible). You get execution errors if you try say:


put the charIndex of word 8 of the text of the templateField

put the charIndex of word 8 of the templateField

put the charIndex of word 8 of tVar

Does anyone know of a clever way to do the equivalent of the charIndex 
for an arbitrary chunk expression for a container/variable (i.e. not an 
actual field object)?


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode