~indicator-multiload/indicator-multiload/trunk

« back to all changes in this revision

Viewing changes to src/expressionparser.vala

  • Committer: mh21 at mh21
  • Date: 2017-02-24 11:53:48 UTC
  • Revision ID: mh21@mh21.de-20170224115348-qnslmzm6f9x0wu0m
Add size2 function with IEC units (base 2).

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
 
178
178
    private uint index;
179
179
    private string[] tokens;
180
 
    bool guide;
181
180
 
182
181
    public ExpressionEvaluator(Providers providers) {
183
182
        this.providers = providers;
327
326
            bool found = false;
328
327
            try {
329
328
                var result = this.providers.call(token, this.params(),
330
 
                        this.guide, out found);
 
329
                        out found);
331
330
                if (!found)
332
331
                    throw error(nameindex, "unknown function");
333
332
                return (sign == -1 ? "-" : "") + result;
365
364
        return string.joinv("", result);
366
365
    }
367
366
 
368
 
    public string evaluate(string[] tokens, bool guide) {
 
367
    public string evaluate(string[] tokens) {
369
368
        this.index = 0;
370
369
        this.tokens = tokens;
371
 
        this.guide = guide;
372
370
        try {
373
371
            return text();
374
372
        } catch (Error e) {
393
391
 
394
392
    private string[] _tokens;
395
393
    private string _label;
396
 
    private string _guide;
397
394
 
398
395
    private string _expression;
399
396
    public string expression {
404
401
            this._expression = value;
405
402
            this._tokens = null;
406
403
            this._label = null;
407
 
            this._guide = null;
408
404
        }
409
405
    }
410
406
 
414
410
 
415
411
    public void update() {
416
412
        this._label = null;
417
 
        this._guide = null;
418
413
    }
419
414
 
420
415
    public string[] tokens() {
425
420
 
426
421
    public string label() {
427
422
        if (this._label == null)
428
 
            this._label = new ExpressionEvaluator(this.providers).evaluate(this.tokens(), false);
 
423
            this._label = new ExpressionEvaluator(this.providers).evaluate(this.tokens());
429
424
        return this._label;
430
425
    }
431
 
 
432
 
    public string guide() {
433
 
        if (this._guide == null)
434
 
            this._guide = new ExpressionEvaluator(this.providers).evaluate(this.tokens(), true);
435
 
        return this._guide;
436
 
    }
437
 
 
438
426
}
439
427