Complete

WERETECH-10739

Fixed

Bug in compilator , with String.equals and utf8 symbol

Function Always show false, but symbol the same. 

var dTExt = "";  

Toybox.System.println( ((dTExt.equals("") ))  );  


  • Yes. ) now to equal that symbols i just added other not utf8 symbol. 
    I long time didn't understand, why simple function give my wrong results) 

    *offtop 
    In suggestion  add  a callback function to the sdk WatchUi.WatchFace 
    Determinate when something drawing on the screen message like: ("Connection lost/established", "Low phone battery", "chime o'clock")
    run before the last onUpdate() calling
    Function very needed for energy efficient wachface. Now i wrote "crutches" instead  of her  (by counting the number of step-by-step onUpdate calls)

  • Okay, I think I finally understand. Your original post said that symbol the same, but that is not the case. The utf8 code points are indeed different. Here is a test case that illustrates the problem much more clearly and avoids the possibility of the utf8 characters getting munged by the forum software.

    //var a = "";
    var a = "\uEACA";
    		
    //var b = "";
    var b = "\uEACB";
    		
    System.println(a.equals(b));
    System.println(b.equals(a));

    This incorrectly prints

    true
    true

    If I append another character (say "Z") to the strings, then the difference is properly detected.

  • You equal  only 1 symbol 
    try diferent:
    1:  

    2: 

    code of symbols  and 

    This bug  i was get when redraw new icon from font, and check new with old text  

  • I can't reproduce. Here is the source for my test app.

    using Toybox.Application;
    using Toybox.WatchUi;
    using Toybox.System;
    
    function as_hex_bytes(s) {
    	var r = [];
    	
    	var a = s.toUtf8Array();
    	for (var i = 0; i < a.size(); ++i) {
    		r.add("\\x" + a[i].format("%X"));
    	}
    	
    	return r;
    }
    
    function as_code_points(s) {
    	var r = [];
    	
    	var a = s.toCharArray();
    	for (var i = 0; i < a.size(); ++i) {
    		r.add(a[i].toNumber());
    	}
    	
    	return r;
    }
    
    function as_unicode_escapes(s) {
    	var r = [];
    	
    	var a = s.toCharArray();
    	for (var i = 0; i < a.size(); ++i) {
    		r.add("\\u" + a[i].toNumber().format("%X"));
    	}
    	
    	return r;
    }
    
    class ForumTestApp extends Application.AppBase {
    
        function initialize() {
            AppBase.initialize();
            
    		var s = "";
    		// var s = "\uEACA";
    		System.println(s);
    		
    		System.println(as_hex_bytes(s));
    		System.println(as_code_points(s));
    		System.println(as_unicode_escapes(s));
    	
    		System.println(s.equals(s));
    		System.println(s.equals(""));
    		System.println("".equals(s));
    		System.println(s.equals("\uEACA"));
    		System.println("\uEACA".equals(s));
        }
    
        function getInitialView() {
            return [ new WatchUi.View() ];
        }
    
    }
    

    The output in the eclipse console is:

    
    [\xEE, \xAB, \x8A]
    [60106]
    [\uEACA]
    true
    true
    true
    true
    true
    

  • Sorry i give you wrong start data 
    Its old bug, foget how it work

    //code 60106  ,  code60107  - 0ff

    allways show true, but symbol not equal , tested now on 3.2.5 


    var dTExt = "";
    Toybox.System.println( ((dTExt.equals("") )) );

    if i add "1" to both text - function show false 

    //60106  - on 60107  - 0ff
    var dTExt = "1";
    Toybox.System.println( ((dTExt.equals("1") )) );

    thats how i fix this isue