Example #1
0
void test_Atom_length(void)
{
   atom = Atom_string(msg);
   CU_ASSERT_EQUAL(Atom_length(atom), strlen(msg));
   
   atom = Atom_new(msg, strlen(msg) + 1);
   CU_ASSERT_NOT_EQUAL(Atom_length(atom), strlen(msg));
}
Example #2
0
const char *Atom_int(long n){
	char str[43];
	char *s = str + sizeof(str);
	unsigned long m;
	if (n == LONG_MIN)
		m = LONG_MAX + 1UL;
	else if (n<0)
		m = -n;
	else
		m = n;
	do
		*--s = m%10 + '0';
	while ((m /= 10) > 0);
		if (n < 0)
			*--s = '-';
	return Atom_new(s, (str + sizeof(str)) - s);
}
Example #3
0
const char *Atom_int(long n)
{
	char str[43];
	char *s = str + sizeof(str); /* puntatore all'ultimo elemento della stringa */
	unsigned long m;             /* intero di appoggio */

	/* Calcolo il valore assoluto di n e lo salvo in m */
	if( n == LONG_MIN )
	{
		/* se n è uguale al minimo numero rappresentabile con segno, non è
		 * possibile rappresentarne il valore assoluto poiché nel sistema
		 * complemento a 2 c'è un numero negativo in più
		 * */
		m = LONG_MAX + 1UL;
	}
	else if( n < 0 )
	{
		m = -n;
	}
	else
	{
		m = n;
	}

	/* Partendo da destra verso sinistra, costruisco la rappresentazione
	 * decimale della stringa: prendo la cifra più a destra, divido m per 10 e
	 * continuo finché m non diventa 0.
	 * Man mano che il numero viene processato, le cifre vengono memorizzate in
	 * --s, che percorre str da destra verso sinistra.
	 * Se n è un numero negativo, viene inserito un segno - 
	 * */
	do
	{
		*--s = m%10 + '0';
	} while( (m /= 10) > 0 );

	if( n < 0 )
	{
		*--s = '-';
	}
    /* Al termine del processo, s punta alla stringa desiderata. Questa stringa
     * contiene &str - s caratteri.
     * */
	return Atom_new(s, (str + sizeof(str)) - s);
}
Example #4
0
File: atom.c Project: lucabol/llib
const char *Atom_int(long n) {
    char str[43];
    char *s = str + sizeof str;
    unsigned long m;

    if (n == LONG_MIN)
        m = LONG_MAX + 1UL;
    else if (n < 0)
        m = (unsigned long) (-n);
    else
        m = (unsigned long) n;
    do
        *--s = (char) (m%10 + '0');
    while ((m /= 10) > 0);
    if (n < 0)
        *--s = '-';
    return Atom_new(s, (size_t)((str + sizeof str) - s));
}
Example #5
0
const char *Atom_string(const char *str)
{
	assert(str);
	return Atom_new(str, strlen(str));
}
Example #6
0
char *stringn(const char *str, int len) {
	return (char *)Atom_new(str, len);
}