qexo-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qexo-general] string functions implemented


From: Terje Pedersen
Subject: [Qexo-general] string functions implemented
Date: Thu, 24 Jul 2003 03:15:47 +0200
User-agent: KMail/1.5.1

>Re: [Qexo-general] Support for parent:: axis??
>Hi,
>Thanks for your reply.  I understand about not making commitments.  It would
>be great to add the translate() and contains() function on the wish list too
>:-)
>Cheers,
>Craig.

I have now implemented both the translate() and contains() functions and also 
the string-length(), substring-before(), substring-after(), string-pad(), 
starts-with(), ends-with() and string-join() I haven't done anything about 
collations. Below I have presented the two wanted functions. (All of these 
functions is sent to Per) 

I would really preciate comments on my code.

  public static Object translate (Object str, Object map, Object trans)
  {
    if(str == Values.empty || map == Values.empty || trans == Values.empty)
        return Values.empty;

    String m = map.toString();
    int mlen = m.length();

    if(mlen==0) return str.toString();

    String t = trans.toString();
    StringBuffer s = new StringBuffer(str.toString());
    int slen = s.length();
    int tlen = t.length();

    for(int i=0;i < slen;i++)
    {
        for(int j=0;j<mlen;j++)
        {
          if(s.charAt(i)==m.charAt(j))
           {
                if(j<tlen) { s.setCharAt(i,t.charAt(j)); }
                else { s.deleteCharAt(i--); slen--; }
                continue;
          }
        }
    }

  public static Object contains (Object str, Object contain)
  {
    if(str == Values.empty || contain == Values.empty)
        return Values.empty;

   String s = str.toString();
   String c = contain.toString();

    if(c.length()==0) return Boolean.TRUE;
    if(s.length()==0 && c.length()>0) return Boolean.FALSE;

    return s.indexOf(c)<0? Boolean.FALSE : Boolean.TRUE;
  }


So now is it possible also in Qexo (my build of kawa) to do things like:

let $rss := doc("rss.xml")
for $item in $rss/rss/channel/item
where contains(string($item/title),"me")
return $item/title

gives all title nodes where the the title contains me

let $d := doc("rss.xml")/rss/channel/item
for $a in $d
let $title :=string($a/title/text()), $l := string-length($title)
where $l > 10 and $l < 20
return element t {$title}

gives an element t of each title where length of the title is between 10 and 
20 chars


Terje Pedersen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]