File: isinstring.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (48 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function r=isinstring(str,pos)
// Copyright INRIA
str=part(str,1:pos-1)
if strindex(str,quote)==[] then
  r=%f
  return
end

ksym=0  
strcnt=0
qcount=0
bcount=0
pcount=0
sym=' '
while %t ,
  while %t then
    if ksym>=pos then
      r=strcnt<>0
      return
    end
    ksym=ksym+1
    psym=sym
    sym=part(str,ksym);
    if sym<>' ' then break,end
  end
  if  strcnt<>0 then
    if sym==quote then
      qcount=0
      qcount=qcount+1
      while part(str,ksym+1)<>quote&ksym+1<pos then ksym=ksym+1,end
      if 2*int(qcount/2)<>qcount then  strcnt=0,sym=' ',end
    end
    //disp([1 strcnt,qcount,bcount]),halt()
  elseif sym==quote then
    // check if transpose or beginning of a string
    if abs(str2code(psym))>=36&psym<>')'&psym<>']'&psym<>'.'&psym<>quote then
      strcnt=1
    elseif bcount<>0 then
      if part(str,ksym-1)==' ' then strcnt=1,end
    end
    //disp([0 strcnt,qcount,bcount]),halt()
  elseif sym=='[' then
    bcount=bcount+1
  elseif sym==']' then
    bcount=bcount-1
  end
end