If you want to count the number of white spaces character you could do:
let l = getline('.')
let n = len(l) - match(l, '\s*$')
If you want to count the number of white spaces you could do:
let bnr = bufnr('%')
let winid = bufwind(bnr)
let r = line('.')
let l = getline(r)
let c0 = match(l, '\s*$') - 1
let c1 = len(l) + 1
let n0 = screenpos(winid, r, c0)
let n1 = screenpos(winid, r, c1)
let n = n1 - n0