-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquestions.go
69 lines (57 loc) · 2.13 KB
/
questions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"unicode/utf16"
)
// QuestionTextInfo contains the offsets for the
// question, responses and language.
type QuestionTextInfo struct {
LanguageCode uint8
QuestionOffset uint32
Response1Offset uint32
Response2Offset uint32
}
type QuestionText struct {
Question []uint16
Response1 []uint16
Response2 []uint16
}
// MakeQuestionsTable generates the metadata for questions.
func (v *Votes) MakeQuestionsTable() {
v.Header.QuestionTextInfoTableOffset = v.GetCurrentSize()
// Get all the questions for the current country.
for _, _ = range append(append([]Question{}, nationalQuestions...), worldwideQuestion) {
for _, language := range GetSupportedLanguages(v.currentCountryCode) {
v.QuestionTextInfoTable = append(v.QuestionTextInfoTable, QuestionTextInfo{
LanguageCode: uint8(language),
QuestionOffset: 0,
Response1Offset: 0,
Response2Offset: 0,
})
}
}
// Now the text
index := 0
for _, question := range append(append([]Question{}, nationalQuestions...), worldwideQuestion) {
for _, language := range GetSupportedLanguages(v.currentCountryCode) {
v.QuestionTextInfoTable[index].QuestionOffset = v.GetCurrentSize()
questionText := QuestionText{
Question: utf16.Encode([]rune(v.GetQuestionForLanguage(question, language))),
Response1: []uint16{},
Response2: []uint16{},
}
// Apply 2 bytes of padding
questionText.Question = append(questionText.Question, uint16(0))
v.QuestionText = append(v.QuestionText, questionText)
// Response 1
v.QuestionTextInfoTable[index].Response1Offset = v.GetCurrentSize()
v.QuestionText[index].Response1 = utf16.Encode([]rune(v.GetResponse1ForLanguage(question, language)))
v.QuestionText[index].Response1 = append(v.QuestionText[index].Response1, uint16(0))
// Response 2
v.QuestionTextInfoTable[index].Response2Offset = v.GetCurrentSize()
v.QuestionText[index].Response2 = utf16.Encode([]rune(v.GetResponse2ForLanguage(question, language)))
v.QuestionText[index].Response2 = append(v.QuestionText[index].Response2, uint16(0))
index++
}
}
v.Header.NumberOfQuestions = uint8(len(v.QuestionTextInfoTable))
}