r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Gregg
5-Apr-2006
[307]
We wanted to use it too Brian, but it wasn't up to what we asked 
of it (View being important).
Pekr
5-Apr-2006
[308]
it is overall interesting issue - to get rebol running on various 
platforms in a way so it adheres to particular platform habits .... 
OS-X, WinCE being reported as Rebol feeling kind of hostile there 
...
Henrik
5-Apr-2006
[309]
it probably amounts to have rebol being more flexible with the types 
of windows and interfaces it can make... currently, just being able 
to create one type of windows isn't enough for more and more platforms.
Julia
13-Apr-2006
[310]
could you help me with parsing? what is the best way to change value 
of "src"'s in html document to another value?
Henrik
13-Apr-2006
[311]
probably through old fashioned search/replace
Anton
13-Apr-2006
[312x2]
Parse is probably the best way.
I presume just src of image tags ?
Julia
13-Apr-2006
[314x2]
yes
about mobile... is it plannig rebol/view 1.3.2 for win mobile 5.0? 
I want to see power and buty of rebol/view on vga(640/480) handheld 
screen :)
Henrik
13-Apr-2006
[316]
julia, http://www.rebol.net/article/0217.html<--- this is the closest 
hint we have so far
Julia
13-Apr-2006
[317]
thanks
Anton
14-Apr-2006
[318x4]
Julia, I have just written this so it's not well-tested:
page: read http://www.rebol.com

images: copy []

use [whsp ws non-end-tag strd p1 p2 delim non-delim][

	whsp: charset " ^-^/" ; whitespace
	ws: [any whsp] ; a rule for any number of whitespace characters
	non-end-tag: complement charset ">" ; all characters except ">"
	strd: charset {"'} ; string delimiters, double and single quote
	parse/all page [
		any [
			thru "<img" [
				ws "src" ws "=" ws 

    p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement 
    union whsp charset delim)

    p1: any non-delim p2: (append images copy/part p1 p2) ; keep the 
    url
				| non-end-tag
			] | skip
		]
	]

]


new-line/all images on ; add hidden newlines to the images block 
so it molds nicely
print mold images
It sounds like you want to modify the image links in place, so we 
can show you how to do that safely, too.
I should mention some characteristics of the above parse rule.

Since it does not parse html, its detection of real img tags is simple 
and cannot determine the context in which the string  "<img" is found. 
 For instance, there might be written some code in a preformatted 
text section, eg:
	<pre>
		<img src="...">
	</pre>

Such a section should be left alone by the parser as it is not "inside" 
the html.
Unfortunately, making a full html parser is not so easy...
But you may find the above rule is sufficient for your needs.
Alek_K
14-Apr-2006
[322]
'alt' and other atributes can be before img -> <img alt="picture" 
src="picture.jpg"/>
Anton
14-Apr-2006
[323]
Thankyou Alek, you are right.... hmm..
Alek_K
14-Apr-2006
[324]
about <pre> - html tags inside are permitted
Anton
14-Apr-2006
[325]
Yes, but they shouldn't be touched, should they ?
Alek_K
14-Apr-2006
[326]
But images are excluded from this :)
Anton
14-Apr-2006
[327]
I understand you, but maybe I didn't make myself clear above.
Alek_K
14-Apr-2006
[328x2]
Maybe I didn't  :) - <img> inside <pre> are not permited (as w3c 
states) - but IE / Opera / Firefox displays it
so changing src in it - is all way expected as for now
Anton
14-Apr-2006
[330]
Hmm... that's a strange rule. I thought that any text could be inside 
<pre> ... </pre> so that you could put code in. I don't claim to 
have a real indepth knowledge of html, though. I try to avoid it. 
:)
Alek_K
14-Apr-2006
[331]
If You want to show html code in <pre> - You should use &gt; for 
> and &lt; for <
Anton
14-Apr-2006
[332x3]
Ok, here is a version that should skip other attributes.
page: read http://www.rebol.com
images: copy []

use [whsp ws non-end-tag strd p1 p2 delim non-delim][

	whsp: charset " ^-^/" ; whitespace
	ws: [any whsp] ; a rule for any number of whitespace characters
	non-end-tag: complement charset ">" ; all characters except ">"
	strd: charset {"'} ; string delimiters, double and single quote
	parse/all page [
		any [
			thru "<img" whsp [
				any [
					ws "src" ws "=" ws 

     p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement 
     union whsp charset delim)

     p1: any non-delim p2: (append images copy/part p1 p2) ; keep the 
     url
					| non-end-tag 
				]
			] | skip
		]
	]

]


new-line/all images on ; add hidden newlines to the images block 
so it molds nicely
print mold images
Ah yes.
Alek_K
14-Apr-2006
[335x2]
one more - value in quotes can contain whitespaces - it is ok to 
have <img src="one two.jpg">
and second - one can write <img alt="picture" src=one.jpg /> - which 
is also good - and besides that IMO all is OK.
Anton
14-Apr-2006
[337]
Really ? "one two.jpg" doesn't have to have the space url encoded 
?
Gabriele
14-Apr-2006
[338x2]
no, quotes are for that.
also, in xhtml quotes are mandatory
Anton
14-Apr-2006
[340x2]
Hmm... OK then, here's the fixed version:
page: read http://www.rebol.com
; special test cases from Alek_K
;page: {<img src="one two.jpg">} ; OK
;page: {<img alt="picture" src=one.jpg />} ; OK
images: copy []


use [whsp ws non-end-tag strd wh- non-str-delim p1 p2 delim non-delim][

	whsp: charset " ^-^/" ; whitespace
	ws: [any whsp] ; a rule for any number of whitespace characters
	non-end-tag: complement charset ">" ; all characters except ">"
	strd: charset {"'} ; string delimiters, double and single quote


 wh-: charset "^-^/" ; whitespace minus the space character (space 
 is allowed inside a quoted string)
	non-str-delim: complement union whsp charset ">"	

	parse/all page [
		any [
			thru "<img" whsp [
				any [
					ws "src" ws "=" ws 

     ;p1: [strd (delim: form p1/1) | (delim: ">")] (non-delim: complement 
     union whsp charset delim)

     p1: [strd (non-delim: complement union wh- charset form p1/1) | (non-delim: 
     non-str-delim)]

     p1: any non-delim p2: (append images copy/part p1 p2) ; keep the 
     url
					| non-end-tag 
				]
			] | skip
		]
	]

]


new-line/all images on ; add hidden newlines to the images block 
so it molds nicely
print mold images
Anton
17-Apr-2006
[342]
Now, the tricky thing with modifying parts of a string in a parse 
rule is that you have to leave the current parse index at the end 
of your new replacement string.

What usually happens is you parse up to your search string, set a 
marker (here it's done with p1:), parse through your search string, 
set another marker (p2:), then

 	(remove/part p1 p2
	insert p1 "my new string")


but if the the new string is shorter or longer than the old string, 
then the parse index will be left in the wrong position.

So to fix that we need to set p2 to p1 plus the length of the new 
string, then set the parse index to that position so it can continue 
as intended:

	(p2: p1 + length? new-string) :p2


So the full example above can modify links in place if you simply 
replace:

	(append images copy/part p1 p2)

with something like:

 	(
		old-string: copy/part p1 p2
		new-string: "create your new link from the old one here"
		remove/part p1 p2
		insert p1 new-string
		p2: p1 + length? new-string
	) :p2
Thør
26-May-2006
[343]
sync attempt...
Normand
21-Jun-2006
[344]
Simple blocks mappings: I looked in the maillist, but did not find 
for such a simple case.  I am trying to devise a function to map 
values from rebDB to the user UI in rebGui.  So I need to map the 
respective values in two blocks, as in a: [a b c d e] and b: [1 2 
3 4 5], thinking that a foreach would do the mapping.  To no avail?
z: []
foreach [i j] [a b] [append z [i j]]
I want [a 1 b 2 c 3 d 4 e 5]

I would need two foreach, side by side, not to embed one in the other. 
This does not work, but the idea is there.
>> z: []
== []
>> foreach i a foreach j b [append z [i j]]
== 5
>> :z
== [i j i j i j i j i j] -> ?What is the formula?
Henrik
21-Jun-2006
[345x2]
I made a function for this to interface MySQL:

keyed: func [keys [block!] values [block!] /local out] [
  out: copy []
  if not any [empty? keys empty? values] [
    repeat i length? keys [
      insert tail out reduce [

        keys/:i either block? first values [values/1/:i][values/:i]
      ]
    ]
  ]
  out
]
>> keyed [a b c] [1 2 3]
== [a 1 b 2 c 3]
Normand
21-Jun-2006
[347]
So usefull.  Thanks.
Anton
22-Jun-2006
[348]
>> a: [a b c d e] b: [1 2 3 4 5] z: [] repeat n length? a [repend 
z [a/:n b/:n]]
== [a 1 b 2 c 3 d 4 e 5]
Normand
29-Jun-2006
[349]
Integer digits of a string: I want to check if all the digits of 
a string, str: "1984", are integer number, to check the validity 
of a date. Ideally I do not want to use integer to-integer, as in:

check: func [ str [string!] ] [ for n 1 (length? str) 1 [integer? 
to-integer to-string pick str 1] ]. It seems to me that to beg the 
question.  Any more elegant way to do that?
Tomc
29-Jun-2006
[350x2]
parse string [integer!]
integer? load string
Henrik
29-Jun-2006
[352]
normand, also remember that rebol can do date checking, so you don't 
have to check that manually as well
BrianH
29-Jun-2006
[353]
Although, only of dates that are in one of the ISO formats.
Henrik
29-Jun-2006
[354]
yes, you need to shape them to that first, but that might be easier 
than the other thing :-)
Geomol
30-Jun-2006
[355x2]
Example:
Let's say, our date is 6 digits YYMMDD.
>> date: "230812"
We deside, it's the year 2023:
>> insert date "20"
Now dashes are inserted to form a date understandable by REBOL:
>> insert skip date 6 "-"
>> insert skip date 4 "-"
Date now looks like this:
>> date
== "2023-08-12"
And we can control, it's a valid date with:
>> to-date date
== 12-Aug-2023

If it's not a valid date, like if the original had other characters 
than digits, we'll get an error. Errors can be caught with:
>> error? try [to-date "foobar"]
== true

Hope it helps.
control = check