Matt,

I would suggest a slightly different approach. I would probably reverse the property and value positions in your two lists. That is, build up a sorted lists like:

list1 = [0:"<text ....", 10: <"text ...."]
list2 = [10:"</text>", 19:"</text>"]

This way, you could walk through each list and check if the the property exists in the other list, something like this (tested with only your data):

on test
  List1 = [0: "<text align='right'>", 10: "<text align='left'>"]
  List2 = [10: "</text>", 19: "</text>"]
  mergedList = combineLists(List1, List2)
  put mergedList
end

on combineLists list1, list2 numFeatures1 = count(list1)
numFeatures2 = count(list2)


  if numFeatures1 < numFeatures2 then
    smallerList = list1  -- doesn't copy, just sets a pointer
    largerList = list2
    numInSmallerList = numFeatures1
  else
    smallerList = list2
    largerList = list1
    numInSmallerList = numFeatures2
  end if

outputList = duplicate(largerList) -- make a copy the larger list as a starting point
sort(outputList)


-- now loop through the items in the smaller list. -- If an item is not in the output list, add the property and the value
-- else there is a match on a property in the larger list, add to the existing value string


  repeat with i = 1 to numInSmallerList
    theProp = getPropAt(smallerList, i)
    theValue = smallerList[i]
    where = getAProp(outputList, theProp)

if voidp(where) then -- not found addProp(outputList, theProp, theValue)
else -- found a match
theExistingValue = getAProp(outputList, theProp)
theExpandedValue = theExistingValue & theValue
setProp(outputList, theProp, theExpandedValue)
end if
end repeat
return(outputList)
end


This gives you a merged list with the properties and values reversed:

-- [0: "<text align='right'>", 10: "<text align='left'></text>", 19: "</text>"]

Hope this helps,

Irv

PS:  You have to be careful about quote marks within your strings, e.g.,

"text align="right">"

is not a valid Lingo string  (I faked it for this test)

Irv



At 3:32 PM -0500 7/22/04, Matt Wells wrote:
I was wondering if you guys could give me a hand with this.

I'm creating a HTML editor and I have come across this problem. I look
at each char in the text and place what it is in a list like what you
see below.

** Now I need to find in each list the ones with matching numbers and
combine them.

My two lists:

List1 = ["<text align="right">": 0, "<text align="left">": 10]
List2 = ["</text>": 10, </text>": 19]

What I need is:

List3 = ["<text align="right">": 0, "</text><text align="left">":10,
"</text>": 19]

As you can see now Number 10 in List1 and List2 are combined in List3.

What I have done so far:

on combineLists

  set numFeatures1 =count(list1)
  set numFeatures2 =count(list2)


if numFeatures1 > numFeatures2 then numFeatures = numFeatures1 else numFeatures = numFeatures2 end if

  newlistAlign = [:]

repeat with x = 1 to numFeatures
if x > numFeatures1 then
else
set item1 =getAt(list1, x) --Num
set type1 =getPropAt(list1, x) --Tag
end if
if x > numFeatures2 then
else
set item2 =getAt(list2, x)--Num
set type2 =getPropAt(list2, x)--Tag
end if
if item1 = item2 then
newEntery = type1 & type2
addProp newlist, newEntery, item2
end if
if item1 <> item2 then
newEntery = type1
newEntery2 = type2
addprop newlist, newEntery, item1
addprop newlist, newEntery2, item2
end if


  end repeat

end


Problem is I get this: ["<text align="right">": 0, "</text>": 10, "<text align="left">": 10, "</text>": 19]

Thanks,
Matt



[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]


--

Multimedia Wrangler.
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]

Reply via email to