Coverage Report

Created: 2026-09-04 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/plan9port/src/lib9/fmt/fmtlocale.c
Line
Count
Source
1
/* Copyright (c) 2004 Google Inc.; see LICENSE */
2
3
#include <stdarg.h>
4
#include <string.h>
5
#include "plan9.h"
6
#include "fmt.h"
7
#include "fmtdef.h"
8
9
/*
10
 * Fill in the internationalization stuff in the State structure.
11
 * For nil arguments, provide the sensible defaults:
12
 *  decimal is a period
13
 *  thousands separator is a comma
14
 *  thousands are marked every three digits
15
 */
16
void
17
fmtlocaleinit(Fmt *f, char *decimal, char *thousands, char *grouping)
18
37.6k
{
19
37.6k
  if(decimal == nil || decimal[0] == '\0')
20
37.6k
    decimal = ".";
21
37.6k
  if(thousands == nil)
22
37.6k
    thousands = ",";
23
37.6k
  if(grouping == nil)
24
37.6k
    grouping = "\3";
25
37.6k
  f->decimal = decimal;
26
37.6k
  f->thousands = thousands;
27
37.6k
  f->grouping = grouping;
28
37.6k
}
29
30
/*
31
 * We are about to emit a digit in e.g. %'d.  If that digit would
32
 * overflow a thousands (e.g.) grouping, tell the caller to emit
33
 * the thousands separator.  Always advance the digit counter
34
 * and pointer into the grouping descriptor.
35
 */
36
int
37
__needsep(int *ndig, char **grouping)
38
0
{
39
0
  int group;
40
41
0
  (*ndig)++;
42
0
  group = *(unsigned char*)*grouping;
43
  /* CHAR_MAX means no further grouping. \0 means we got the empty string */
44
0
  if(group == 0xFF || group == 0x7f || group == 0x00)
45
0
    return 0;
46
0
  if(*ndig > group){
47
    /* if we're at end of string, continue with this grouping; else advance */
48
0
    if((*grouping)[1] != '\0')
49
0
      (*grouping)++;
50
0
    *ndig = 1;
51
0
    return 1;
52
0
  }
53
0
  return 0;
54
0
}