1 package com.tapina.robe.swi.clib.string;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.swi.clib.Stub;
5
6 /***
7 * This function works out the length of the string pointed to by a1 (ie the number of characters before the null
8 * terminator).
9 * Returns: Length of the string, or 0 if a1 == NULL.
10 * @todo Write a JUnit test for R0 = 0 so that the behaviour is explicitly documented and tested for. See DrawPlus: baricon()
11 */
12 public class StrLen extends Stub {
13 public void executeStub(Environment environment) {
14 final int[] R = environment.getCpu().R;
15 if (R[0] == 0) {
16 return;
17 }
18 final String string = environment.getMemoryMap().getString0(R[0]);
19 R[0] = string.length();
20 }
21 }