Please help to understand, what is wrong with following code:
    
    
    proc strsubsmart(s: string, start: int, fl0wlen: int): string =
      if start >= 0 and fl0wlen > 0:
        substring(s, start, fl0wlen)
      else:
        var slen: int =
          strlen(s)
        var trueStart: int =
          if start >= 0:
            start
          else:
            var ss: int =
              slen+start
            if ss >= 0:
              ss
            else:
              0
        var trueLength: int =
          if fl0wlen > 0:
            fl0wlen
          else:
            slen+fl0wlen-trueStart
        substring(s, trueStart, trueLength)
    

It produces error

fc.nim(2237, 9) Error: invalid indentation where line 2237 is
    
    
    if ss >= 0:
    

This code is derived from
    
    
    strsubsmart(s : string, start : int, len : int) -> string {
            if (start >= 0 && len > 0) {
                    substring(s, start, len)
            } else {
                    slen = strlen(s);
                    trueStart = if (start >= 0) start else { ss = slen + start; 
if (ss >= 0) ss else 0; };
                    trueLength = if (len > 0) len else slen + len - trueStart;
                    
                    substring(s, trueStart, trueLength)
            }
    }
    

'if' expression with issue follows var declaration in one code block and is a 
result of outer if expression.

Reply via email to