<p>All work and no play makes Jack a dull boy</p> !(=^..^=)!

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by [-hh] » Fri Jul 08, 2016 12:15 pm

The "fast LC 6"-version (from above) works of course also with LC 7/8.
[But LC 7/8 needs up to 50% more time than LC 6.]

I hope that you will show us your artwork when finished.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by FourthWorld » Fri Jul 08, 2016 6:26 pm

With both methods here taking only microseconds the speed difference hardly matters much, but FWIW exploring other ways to solve this lends itself to a very lazy option:

Code: Select all

on mouseUp
  put fld 1 into tHtml
  put 1000 into n
  --
  put the millisecs into t
  repeat n
    put ReformatHtml1(tHtml) into r1
  end repeat
  put the millisecs - t into t1
  --
  put the millisecs into t
  repeat n
    put ReformatHtml2(tHtml) into r2
  end repeat
  put the millisecs - t into t2
  --
  put "Method 1: "& (t1/n)&" ms" &cr \
        & "Method 2: "& (t2/n) &" ms" &cr \
        & "Same result?: "& (r1=r2)
end mouseUp

function ReformatHtml1 pHtml
  put the num of lines of pHtml into n1
  put numToChar(1) into c1
  put numToChar(2) into c2
  replace "<p>" with c1 in pHTml
  replace "</p>" with c2 in pHtml
  set linedel to c1; set itemdel to c2
  put line 1 of pHtml into txt2 --> we start AFTER first "<p>"
  repeat for each line L in (line 2 to -1 of pHtml)
    replace cr with space in item 1 of L
    replace c2 with "</p>" in L
    put "<p>" & L after txt2
  end repeat
  if last char of txt2 = cr then delete last char of txt2
  return txt2
end ReformatHtml1

function ReformatHtml2 pHtml
  replace cr with space in pHtml
  replace "> <" with ">"&cr&"<" in pHtml
  if last char of pHtml = space then delete last char of pHtml
  return pHTml
end ReformatHtml2
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by [-hh] » Fri Jul 08, 2016 6:48 pm

Your code does the same for MariaSole's very special sample input.
But you overlooked the more general objective:

Replace cr by space between each opening "<p>" and closing "</p>".
Nowhere else, everything else should remain the same no matter the chars.


So simply insert a single return around the midth of the first line and/or the last line of her sample input to see your code fail. You don't know where the return you replaced by space was located ...
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by FourthWorld » Fri Jul 08, 2016 7:07 pm

Thanks. Seems I missed a later post; my understand of the desired output was based on her "What I'd like to see" block here:
http://forums.livecode.com/viewtopic.ph ... 79#p144411

Either way, at a few microseconds per run just about any working method discussed in this thread seems quite good.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by Thierry » Mon Jul 18, 2016 3:07 pm

Mariasole wrote:Grazie [-hh]! :D
Hi Mariasole,

Coming a bit late to the party, being busy on another planet...

Concerning your regex, you jumped into 2 holes:

1) copy/paste a regex from a website to LC won't work all the time.
There are few things to consider doing this...

2) Considering 1) is resolved, then you hit a LC bug.

Anyway, you had your hero ( Hermann) who came to the rescue.

Good luck with your porject,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Post by Mariasole » Mon Jul 18, 2016 6:20 pm

Hi Thierry!
Merci pour ton épiphanie, je pense que le X sur la fenêtre avec la lumière ne fonctionne plus!
While you were on the road for some kind of planets, fortunately the brave Hermann came to save me!
How would I do without you, my knights! :D
Thank you for signing remembered and ... if you revise the X on the window, you think I'm calling you (if you want, instead of X, I will write the string (?:^((?:X)))) 8)

Un bacio!

Mariasole
(=^..^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Post Reply