File: pa_charsets.C

package info (click to toggle)
parser 3.4.5-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,552 kB
  • sloc: cpp: 32,375; sh: 11,487; ansic: 10,849; yacc: 1,361; makefile: 248; awk: 5
file content (60 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download
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
/** @file
	Parser: sql driver manager implementation.

	Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
	Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
*/

#include "pa_charsets.h"

volatile const char * IDENT_PA_CHARSETS_C="$Id: pa_charsets.C,v 1.24 2017/02/07 22:00:41 moko Exp $" IDENT_PA_CHARSETS_H;

// defines for globals

#define CHARSET_UTF8_NAME "UTF-8"

// globals

Charset pa_UTF8_charset(0, *new String(CHARSET_UTF8_NAME), 0/*no file=system*/);

Charsets pa_charsets;

// methods

Charsets::Charsets() {
	put(pa_UTF8_charset.NAME(), &pa_UTF8_charset);
}

Charset& Charsets::get(String::Body ANAME) {
	ANAME=str_upper(ANAME.cstr(), ANAME.length());
	if(Charset* result=HashString<value_type>::get(ANAME))
		return *result;
	else
		throw Exception(PARSER_RUNTIME, new String(ANAME, String::L_TAINTED), "unknown charset");
}

Charset& Charsets::get_direct(const char *ANAME) {
	if(Charset* result=HashString<value_type>::get(ANAME))
		return *result;
	else
		throw Exception(PARSER_RUNTIME, new String(ANAME, String::L_TAINTED), "unknown charset");
}

Charset* Charsets::checkBOM(char *&body,size_t &body_size, Charset* enforced_charset){
	if((!enforced_charset || enforced_charset->isUTF8()) && (body_size>=3 && strncmp(body, "\xEF\xBB\xBF", 3)==0)){
		// skip UTF-8 signature (BOM code)
		body+=3;
		body_size-=3;
		return &pa_UTF8_charset;
	}
	return enforced_charset;
}

void Charsets::load_charset(Request_charsets& charsets, String::Body ANAME, const String& afile_spec) {
	ANAME=str_upper(ANAME.cstr(), ANAME.length());
	//we know that charset?
	if(HashString<value_type>::get(ANAME))
		return; // don't load it then

	put(ANAME, new Charset(&charsets, ANAME, &afile_spec));
}