Posiblyquotename issue?

Dear all,

I am using version 6.2.2.2.

I wrote a function (which used to work fine) which automatically quote the path name of the waves which are availiable.

FUNCTION/S Quoted(path)
string path
variable i

for(i=0;i<itemsinlist(path,":");i+=1)
path=ReplaceString(StringFromList(i, path,":"), path, PossiblyQuoteName(StringFromList(i, path,":")))
endfor
return path

END


I noticed last week that the output of this function gives me now a wrong path. E.g. for a wave with the path root:Data:0708M9:0708M9_up, the function returns root:Data:'0708M9':'0708M9'_up which in turn induces a lot of other errors in my other function.

I did not noticed such errors before. Maybe something changed in the code of the igor functions changed?
Does someone have an idea?
I have a hard time understanding your function because you are using the path string as both and input (3 times) and an output in the same statement and repeating this in a loop. That's hard to think about.

I tried it in Igor Pro 6.06, 6.12 and 6.22A and got the same result (root:Data:'0708M9':'0708M9'_up). However PossiblyQuoteName("0708M9_up") returns the right thing in all versions.

Here is my rewrite of your function to make it clearer. Also it returns the right thing for "root:Data:0708M9:0708M9_up".

FUNCTION/S PossiblyQuotePath(path)
    String path
 
    Variable len = strlen(path)
    if (len == 0)
        return ""
    endif

    String pathOut = ""

    Variable i
    Variable numItems = ItemsInList(path,":")
    for(i=0; i<numItems; i+=1)
        String item = StringFromList(i, path,":")
        String quotedItem = PossiblyQuoteName(item)
        if (strlen(pathOut) > 0)
            pathOut += ":"
        endif
        pathOut += quotedItem
        // Printf "%d, \"%s\", \"%s\", \"%s\"\r", i, item, quotedItem, pathOut
    endfor
   
    String lastChar
    lastChar = path[len-1]
    if (CmpStr(lastChar,":") == 0)
        pathOut += ":"
    endif
   
    return pathOut
End
<pre><code class="language-igor">
I figured out why your version does not work. Because ReplaceString, by default, replaces ALL occurrences of the string and "0708M9" occurs twice in your path.

You can fix this by adding ", 0, 1" to the end of your ReplaceString call. This sets two optional parameters, caseSensitive=0 and maxReplacements=1.

I still prefer my version because it is easier to understand.