asherkin@263: /* vim: set ts=4 sw=4 tw=99 et: asherkin@263: * asherkin@263: * Copyright (C) 2012 David Anderson asherkin@263: * asherkin@263: * This file is part of JITCraft. asherkin@263: * asherkin@263: * JITCraft is free software: you can redistribute it and/or modify it under asherkin@263: * the terms of the GNU General Public License as published by the Free asherkin@263: * Software Foundation, either version 3 of the License, or (at your option) asherkin@263: * any later version. asherkin@263: * asherkin@263: * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY asherkin@263: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS asherkin@263: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. asherkin@263: * asherkin@263: * You should have received a copy of the GNU General Public License along with asherkin@263: * JITCraft. If not, see http://www.gnu.org/licenses/. asherkin@263: */ asherkin@263: #include asherkin@263: #include "Strings.h" asherkin@263: #include "Zone.h" asherkin@263: #include "Heap-inl.h" asherkin@263: asherkin@263: using namespace ke; asherkin@263: asherkin@263: String * asherkin@263: String::New(Zone *zone, const char *from, Heap::Tenure tenure) asherkin@263: { asherkin@263: return New(zone, from, strlen(from), tenure); asherkin@263: } asherkin@263: asherkin@263: String * asherkin@263: String::New(Zone *zone, const char *from, size_t length, Heap::Tenure tenure) asherkin@263: { asherkin@263: size_t bytes = SizeFor(length); asherkin@263: Local string(zone, String::cast(zone->allocate(MapKind_String, bytes, tenure))); asherkin@263: if (!string) asherkin@263: return NULL; asherkin@263: asherkin@263: string->length_ = length; asherkin@263: memcpy(string->chars(), from, length + 1); asherkin@263: asherkin@263: return string; asherkin@263: }