blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 4 201 | content_id stringlengths 40 40 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | repo_name stringlengths 7 100 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 260
values | visit_date timestamp[us] | revision_date timestamp[us] | committer_date timestamp[us] | github_id int64 11.4k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 17
values | gha_event_created_at timestamp[us] | gha_created_at timestamp[us] | gha_language stringclasses 80
values | src_encoding stringclasses 28
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 2
classes | length_bytes int64 8 9.86M | extension stringclasses 52
values | content stringlengths 8 9.86M | authors listlengths 1 1 | author stringlengths 0 119 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
df49784ea7e5db27dbd3d246e163901a808471df | fc4ec8267bc50bbc38da9894542fddfbf08a3ae4 | /freecad-0.14.3702/src/Mod/Part/App/BezierSurfacePyImp.cpp | 1069fc38d39c07ba14c34d2a0a82b35df18eada2 | [] | no_license | AlexandreRivet/HomeMaker | c6252aa864780732dd675ab26e5474d84aa7e5f4 | f483afea21c915e9208cb360046942a0fb26011c | refs/heads/master | 2020-12-24T15:58:53.228813 | 2015-02-01T22:21:11 | 2015-02-01T22:21:11 | 29,052,719 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 25,432 | cpp | /***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Geom_BezierCurve.hxx>
# include <Geom_BezierSurface.hxx>
# include <Handle_Geom_BezierCurve.hxx>
# include <TColStd_Array1OfReal.hxx>
# include <TColStd_Array2OfReal.hxx>
# include <TColgp_Array1OfPnt.hxx>
# include <TColgp_Array2OfPnt.hxx>
#endif
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include "Geometry.h"
#include "BezierCurvePy.h"
#include "BezierSurfacePy.h"
#include "BezierSurfacePy.cpp"
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string BezierSurfacePy::representation(void) const
{
return "<BezierSurface object>";
}
PyObject *BezierSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of BezierSurfacePy and the Twin object
return new BezierSurfacePy(new GeomBezierSurface);
}
// constructor method
int BezierSurfacePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
{
return 0;
}
PyObject* BezierSurfacePy::bounds(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Py::Tuple bound(4);
Standard_Real u1,u2,v1,v2;
surf->Bounds(u1,u2,v1,v2);
bound.setItem(0,Py::Float(u1));
bound.setItem(1,Py::Float(u2));
bound.setItem(2,Py::Float(v1));
bound.setItem(3,Py::Float(v2));
return Py::new_reference_to(bound);
}
PyObject* BezierSurfacePy::isURational(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsURational();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::isVRational(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsVRational();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::isUPeriodic(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsUPeriodic();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::isVPeriodic(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsVPeriodic();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::isUClosed(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsUClosed();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::isVClosed(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_Boolean val = surf->IsVPeriodic();
if (val) {
Py_INCREF(Py_True);
return Py_True;
}
else {
Py_INCREF(Py_False);
return Py_False;
}
}
PyObject* BezierSurfacePy::increase(PyObject *args)
{
int udegree,vdegree;
if (!PyArg_ParseTuple(args, "ii", &udegree, &vdegree))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->Increase(udegree, vdegree);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::insertPoleColAfter(PyObject *args)
{
int vindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->InsertPoleColAfter(vindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->InsertPoleColAfter(vindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::insertPoleRowAfter(PyObject *args)
{
int uindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->InsertPoleRowAfter(uindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->InsertPoleRowAfter(uindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::insertPoleColBefore(PyObject *args)
{
int vindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->InsertPoleColBefore(vindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->InsertPoleColBefore(vindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::insertPoleRowBefore(PyObject *args)
{
int uindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->InsertPoleRowBefore(uindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->InsertPoleRowBefore(uindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::removePoleCol(PyObject *args)
{
int vindex;
if (!PyArg_ParseTuple(args, "i",&vindex))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->RemovePoleCol(vindex);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::removePoleRow(PyObject *args)
{
int uindex;
if (!PyArg_ParseTuple(args, "i",&uindex))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->RemovePoleRow(uindex);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::segment(PyObject *args)
{
Standard_Real u1,u2,v1,v2;
if (!PyArg_ParseTuple(args, "dddd",&u1,&u2,&v1,&v2))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->Segment(u1,u2,v1,v2);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setPole(PyObject *args)
{
int uindex,vindex;
PyObject* obj;
double weight=0.0;
if (!PyArg_ParseTuple(args, "iiO!|d",&uindex,&vindex,&(Base::VectorPy::Type),&obj,&weight))
return 0;
try {
Base::Vector3d pole = static_cast<Base::VectorPy*>(obj)->value();
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (weight <= gp::Resolution())
surf->SetPole(uindex,vindex,gp_Pnt(pole.x,pole.y,pole.z));
else
surf->SetPole(uindex,vindex,gp_Pnt(pole.x,pole.y,pole.z),weight);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setPoleCol(PyObject *args)
{
int vindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->SetPoleCol(vindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->SetPoleCol(vindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setPoleRow(PyObject *args)
{
int uindex;
PyObject* obj;
PyObject* obj2=0;
if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
return 0;
try {
Py::Sequence list(obj);
TColgp_Array1OfPnt poles(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Vector p(*it);
Base::Vector3d v = p.toVector();
poles(index++) = gp_Pnt(v.x,v.y,v.z);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
if (obj2 == 0) {
surf->SetPoleRow(uindex, poles);
}
else {
Py::Sequence list(obj2);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
surf->SetPoleRow(uindex, poles, weights);
}
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::getPole(PyObject *args)
{
int uindex,vindex;
if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_OutOfRange_Raise_if
(uindex < 1 || uindex > surf->NbUPoles() ||
vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range");
gp_Pnt p = surf->Pole(uindex,vindex);
return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z()));
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::getPoles(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
TColgp_Array2OfPnt p(1,surf->NbUPoles(),1,surf->NbVPoles());
surf->Poles(p);
Py::List poles;
for (Standard_Integer i=p.LowerRow(); i<=p.UpperRow(); i++) {
Py::List row;
for (Standard_Integer j=p.LowerCol(); j<=p.UpperCol(); j++) {
const gp_Pnt& pole = p(i,j);
row.append(Py::Object(new Base::VectorPy(
Base::Vector3d(pole.X(),pole.Y(),pole.Z()))));
}
poles.append(row);
}
return Py::new_reference_to(poles);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setWeight(PyObject *args)
{
int uindex,vindex;
double weight;
if (!PyArg_ParseTuple(args, "iid",&uindex,&vindex,&weight))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->SetWeight(uindex,vindex,weight);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setWeightCol(PyObject *args)
{
int vindex;
PyObject* obj;
if (!PyArg_ParseTuple(args, "iO",&vindex,&obj))
return 0;
try {
Py::Sequence list(obj);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->SetWeightCol(vindex, weights);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::setWeightRow(PyObject *args)
{
int uindex;
PyObject* obj;
if (!PyArg_ParseTuple(args, "iO",&uindex,&obj))
return 0;
try {
Py::Sequence list(obj);
TColStd_Array1OfReal weights(1, list.size());
int index=1;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
weights(index++) = (double)Py::Float(*it);
}
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
surf->SetWeightRow(uindex, weights);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::getWeight(PyObject *args)
{
int uindex,vindex;
if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Standard_OutOfRange_Raise_if
(uindex < 1 || uindex > surf->NbUPoles() ||
vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range");
double w = surf->Weight(uindex,vindex);
return Py_BuildValue("d", w);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::getWeights(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
TColStd_Array2OfReal w(1,surf->NbUPoles(),1,surf->NbVPoles());
surf->Weights(w);
Py::List weights;
for (Standard_Integer i=w.LowerRow(); i<=w.UpperRow(); i++) {
Py::List row;
for (Standard_Integer j=w.LowerCol(); j<=w.UpperCol(); j++) {
row.append(Py::Float(w(i,j)));
}
weights.append(row);
}
return Py::new_reference_to(weights);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::getResolution(PyObject *args)
{
double tol;
if (!PyArg_ParseTuple(args, "d", &tol))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
double utol, vtol;
surf->Resolution(tol,utol,vtol);
return Py_BuildValue("(dd)",utol,vtol);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::exchangeUV(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
//FIXME: Crashes
surf->ExchangeUV();
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::uIso(PyObject * args)
{
double u;
if (!PyArg_ParseTuple(args, "d", &u))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Handle_Geom_Curve c = surf->UIso(u);
return new BezierCurvePy(new GeomBezierCurve(Handle_Geom_BezierCurve::DownCast(c)));
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
PyObject* BezierSurfacePy::vIso(PyObject * args)
{
double v;
if (!PyArg_ParseTuple(args, "d", &v))
return 0;
try {
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
Handle_Geom_Curve c = surf->VIso(v);
return new BezierCurvePy(new GeomBezierCurve(Handle_Geom_BezierCurve::DownCast(c)));
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}
Py::Int BezierSurfacePy::getUDegree(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
return Py::Int(surf->UDegree());
}
Py::Int BezierSurfacePy::getVDegree(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
return Py::Int(surf->UDegree());
}
Py::Int BezierSurfacePy::getMaxDegree(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
return Py::Int(surf->MaxDegree());
}
Py::Int BezierSurfacePy::getNbUPoles(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
return Py::Int(surf->NbUPoles());
}
Py::Int BezierSurfacePy::getNbVPoles(void) const
{
Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast
(getGeometryPtr()->handle());
return Py::Int(surf->NbVPoles());
}
PyObject *BezierSurfacePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int BezierSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}
| [
"alex-rivet94@hotmail.fr"
] | alex-rivet94@hotmail.fr |
a7fe328903e6f8f844553ba4c3ef3d7ea3369168 | 20df56bfcab462811b4900abf8500123753ed6b6 | /tSIP/FormHistory.cpp | 6f56ea3e4042137c12f98d1eec28ec3b416e20cb | [
"BSD-3-Clause"
] | permissive | skonst/tSIP | b477ffe3ea45d53a6bba296fcb03d69b0586d0d6 | 242295ccc24b2a1f8ce3c2fe3afaa60c425096b2 | refs/heads/master | 2022-07-21T15:10:46.044594 | 2020-05-12T22:13:17 | 2020-05-12T22:13:17 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,892 | cpp | //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Clipbrd.hpp"
#include "FormHistory.h"
#include "History.h"
#include <assert.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmHistory *frmHistory;
//---------------------------------------------------------------------------
__fastcall TfrmHistory::TfrmHistory(TComponent* Owner, History *history,
CallbackCall callbackCall,
CallbackPhonebookEdit callbackPhonebookEdit,
CallbackHttpQuery callbackHttpQuery
)
: TForm(Owner), history(history),
callbackCall(callbackCall),
callbackPhonebookEdit(callbackPhonebookEdit),
callbackHttpQuery(callbackHttpQuery),
updateNeeded(false), updating(false),
usePaiForDisplayIfAvailable(true),
usePaiForDialIfAvailable(true),
formatCallDurationAsHourMinSec(true),
showCodecNameInHint(true)
{
assert(history);
assert(callbackCall);
assert(callbackPhonebookEdit);
assert(callbackHttpQuery);
history->addObserver(*this);
lvHistory->DoubleBuffered = true;
}
//---------------------------------------------------------------------------
void TfrmHistory::FilterHistory(void)
{
FilteredEntry fentry;
AnsiString needle = UpperCase(edFilter->Text);
filteredEntries.clear();
const std::deque<History::Entry>& entries = history->GetEntries();
if (needle == "")
{
for (int i=0; i<entries.size(); i++)
{
const History::Entry& entry = entries[i];
fentry.id = i;
fentry.entry = entry;
filteredEntries.push_back(fentry);
}
}
else
{
for (int i=0; i<entries.size(); i++)
{
const History::Entry& entry = entries[i];
if (
UpperCase(entry.uri.c_str()).Pos(needle) > 0 ||
UpperCase(entry.peerName.c_str()).Pos(needle) > 0 ||
UpperCase(entry.contactName.c_str()).Pos(needle) > 0 ||
UpperCase(entry.paiUri.c_str()).Pos(needle) > 0 ||
UpperCase(entry.paiPeerName.c_str()).Pos(needle) > 0 ||
UpperCase(entry.paiContactName.c_str()).Pos(needle) > 0
)
{
fentry.id = i;
fentry.entry = entry;
filteredEntries.push_back(fentry);
}
}
}
lvHistory->Items->Count = filteredEntries.size();
lvHistory->Invalidate();
}
void TfrmHistory::SetUpdating(bool state)
{
updating = state;
if (updateNeeded)
{
FilterHistory();
updateNeeded = false;
}
}
void TfrmHistory::obsUpdate(Observable* o, Argument * arg)
{
#if 0
History* history = dynamic_cast<History*>(o);
if (history)
{
//HistoryNotifyArgument* darg = dynamic_cast<HistoryNotifyArgument*>(arg);
//assert(darg);
const std::deque<History::Entry>& entries = history->GetEntries();
lvHistory->Items->Count = entries.size();
lvHistory->Invalidate();
}
#else
/** Delay filtering if history is not visible to reduce CPU load */
if (updating)
{
FilterHistory();
}
else
{
updateNeeded = true;
}
#endif
}
void __fastcall TfrmHistory::lvHistoryData(TObject *Sender, TListItem *Item)
{
int id = Item->Index;
const History::Entry &entry = filteredEntries[id].entry;
int sourceId = filteredEntries[id].id;
AnsiString ts;
ts.sprintf("%02d %02d:%02d:%02d",
entry.timestamp.day,
entry.timestamp.hour, entry.timestamp.min, entry.timestamp.sec);
Item->Caption = ts;
if (usePaiForDisplayIfAvailable && entry.paiUri != "")
{
AnsiString contactName = entry.paiContactName;
if (contactName == "")
{
contactName = entry.paiPeerName;
if (contactName == "")
{
contactName = entry.paiUri;
}
}
Item->SubItems->Add(contactName);
}
else
{
AnsiString contactName = entry.contactName;
if (contactName == "")
{
contactName = entry.peerName;
if (contactName == "")
{
contactName = entry.uri;
}
}
Item->SubItems->Add(contactName);
}
if (entry.incoming)
{
if (entry.time > 0)
Item->ImageIndex = 0;
else
Item->ImageIndex = 1;
}
else
{
if (entry.time > 0)
Item->ImageIndex = 2;
else
Item->ImageIndex = 3;
}
}
//---------------------------------------------------------------------------
History::Entry* TfrmHistory::getSelectedEntry(void)
{
TListItem *item = lvHistory->Selected;
if (item == NULL)
{
return NULL;
}
int id = item->Index;
return &filteredEntries[id].entry;
}
AnsiString TfrmHistory::getDefaultUri(const History::Entry* entry)
{
assert(entry);
if (usePaiForDisplayIfAvailable && entry->paiUri != "")
{
return entry->paiUri;
}
else
{
return entry->uri;
}
}
void __fastcall TfrmHistory::lvHistoryDblClick(TObject *Sender)
{
History::Entry* entry = getSelectedEntry();
if (entry == NULL)
{
return;
}
AnsiString uri = getDefaultUri(entry);
callbackCall(uri.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TfrmHistory::edFilterChange(TObject *Sender)
{
FilterHistory();
}
//---------------------------------------------------------------------------
void __fastcall TfrmHistory::miCopyNumberClick(TObject *Sender)
{
History::Entry* entry = getSelectedEntry();
if (entry == NULL)
{
return;
}
Clipboard()->AsText = getDefaultUri(entry);
}
//---------------------------------------------------------------------------
void __fastcall TfrmHistory::miAddEditPhonebookClick(TObject *Sender)
{
History::Entry* entry = getSelectedEntry();
if (entry == NULL)
{
return;
}
callbackPhonebookEdit(getDefaultUri(entry));
}
//---------------------------------------------------------------------------
void __fastcall TfrmHistory::miHttpQueryClick(TObject *Sender)
{
History::Entry* entry = getSelectedEntry();
if (entry == NULL)
{
return;
}
callbackHttpQuery(getDefaultUri(entry));
}
//---------------------------------------------------------------------------
void __fastcall TfrmHistory::edFilterKeyPress(TObject *Sender, char &Key)
{
TListView *lv = lvHistory;
if (Key == VK_RETURN)
{
if (lv->Items->Count > 0)
{
lv->Items->Item[0]->Selected = true;
lv->Items->Item[0]->Focused = true;
lv->SetFocus();
}
}
}
//---------------------------------------------------------------------------
void TfrmHistory::Scale(int percentage)
{
TListView *lv = lvHistory;
for (int i=0; i<lv->Columns->Count; i++)
{
lv->Columns->Items[i]->Width = (float)lv->Columns->Items[i]->Width * percentage / 100.0f;
}
}
void TfrmHistory::UsePaiForDisplayIfAvailable(bool state)
{
if (usePaiForDisplayIfAvailable != state)
{
usePaiForDisplayIfAvailable = state;
FilterHistory();
}
}
void TfrmHistory::UsePaiForDialIfAvailable(bool state)
{
usePaiForDialIfAvailable = state;
}
AnsiString TfrmHistory::GetHint(TListItem *item)
{
if (item == NULL)
{
return "";
}
int id = item->Index;
const History::Entry &entry = filteredEntries[id].entry;
AnsiString hint;
hint.cat_sprintf("%02d.%02d %02d:%02d:%02d %s%s",
entry.timestamp.month, entry.timestamp.day,
entry.timestamp.hour, entry.timestamp.min, entry.timestamp.sec,
entry.incoming?"Incoming call":"Outgoing call",
entry.time==0?(entry.incoming?" (unanswered)":" (not completed)"):""
);
hint += "\n";
if (usePaiForDisplayIfAvailable)
{
AddPaiToHint(hint, entry);
}
if (entry.uri != entry.paiUri) {
AnsiString contactName = entry.contactName;
if (contactName == "")
{
contactName = entry.peerName;
}
if (contactName != "")
{
hint.cat_sprintf("\n%s %s", contactName.c_str(), entry.uri.c_str());
}
else
{
hint.cat_sprintf("\n%s", entry.uri.c_str());
}
}
if (usePaiForDisplayIfAvailable == false && entry.uri != entry.paiUri)
{
AddPaiToHint(hint, entry);
}
if (entry.time > 0)
{
if (formatCallDurationAsHourMinSec)
{
int hours = entry.time/3600;
int mins = (entry.time - (hours*3600))/60;
int seconds = entry.time % 60;
if (hours > 0)
{
hint.cat_sprintf("\nCall time: %d:%02d:%02d", hours, mins, seconds);
}
else
{
hint.cat_sprintf("\nCall time: %d:%02d", mins, seconds);
}
}
else
{
hint.cat_sprintf("\nCall time: %d s", entry.time);
}
}
if (showCodecNameInHint && entry.codecName != "")
{
hint.cat_sprintf("\nCodec: %s", entry.codecName.c_str());
}
return hint;
}
void TfrmHistory::AddPaiToHint(AnsiString &hint, const History::Entry &entry)
{
if (entry.paiUri != "")
{
AnsiString contactName = entry.paiContactName;
if (contactName == "")
{
contactName = entry.paiPeerName;
}
hint.cat_sprintf("\nPAI: ");
if (contactName != "")
{
hint.cat_sprintf("%s %s", contactName.c_str(), entry.paiUri.c_str());
}
else
{
hint += entry.paiUri;
}
}
}
void __fastcall TfrmHistory::lvHistoryInfoTip(TObject *Sender, TListItem *Item,
AnsiString &InfoTip)
{
if (Item == NULL)
{
return;
}
InfoTip = GetHint(Item);
}
//---------------------------------------------------------------------------
void TfrmHistory::ShowHint(bool state)
{
lvHistory->ShowHint = state;
}
void TfrmHistory::FormatCallDurationAsHourMinSec(bool state)
{
this->formatCallDurationAsHourMinSec = state;
}
std::vector<int> TfrmHistory::GetColumnWidths(void)
{
std::vector<int> widths;
for (int i=0; i<lvHistory->Columns->Count; i++)
{
widths.push_back(lvHistory->Columns->Items[i]->Width);
}
return widths;
}
void TfrmHistory::SetColumnWidths(const std::vector<int>& widths)
{
for (unsigned int i=0; i<widths.size(); i++)
{
if (i >= lvHistory->Columns->Count)
{
break;
}
lvHistory->Columns->Items[i]->Width = widths[i];
}
}
| [
"tomasz.o.ostrowski@gmail.com"
] | tomasz.o.ostrowski@gmail.com |
ad6f3dbb566ffef77375955c5917d8ebc58344d2 | 6e025ee4b8836065cda74ad67b40cd9ec46eb8d8 | /look/src/DisplayDiskSector.cpp | 19cbcb61442bcef0c5d5ce13ac8d35f584ddbeed | [] | no_license | PAntoine/look | bebe3ad2d6ab16a1291bed6736cd52bd91b1f33b | 94a6d1ac9177ad5117acc68107de232046a2950d | refs/heads/master | 2016-09-06T14:22:04.222448 | 2010-01-31T11:22:08 | 2010-01-31T11:22:08 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,452 | cpp | /*--------------------------------------------------------------------------------*
* Name: DriveHexDump
*
* This function will hex dump the drive from the current location for n lines.
* It will also read forward on the disk from the current disk sector.
*
* Author: Peter Antoine.
* Date: 16th July 2001
*--------------------------------------------------------------------------------*/
#ifdef _WIN32
#include <io.h>
#include "ScsiData.h"
#define STDOUT _fileno(stdout)
#else
#include <unistd.h>
#define STDOUT fileno(stdout)
#endif
#include "look.h"
#include <stdio.h>
#include <ctype.h>
extern unsigned long gFileSize;
extern unsigned int gLastLine;
extern unsigned long gDiskSector;
extern unsigned char gSectorBuffer[512];
void DisplayHexLines(unsigned char* inBuffer,int position,int bytesRead,int width);
bool DriveHexDump(int numLines,int width)
{
int count,filePos,lineCount,bytesRead;
for (count=0;count<numLines && gDiskSector < gFileSize;count++)
{
if ((gLastLine % 32) == 0)
{
/* read the new sector */
gLastLine = 0;
if (!Read(gDiskSector,(char*)gSectorBuffer,3))
{
printf("Failed to read sector: %d (%x)\n",gDiskSector,gDiskSector);
break;
}else{
printf("Sector: %d (%x)\n",gDiskSector,gDiskSector);
}
gDiskSector++;
}
DisplayHexLines(gSectorBuffer+gLastLine*16,(gDiskSector-1)*512+gLastLine*16,16,width);
gLastLine++;
}
return (gFileSize<gDiskSector);
}
| [
"github@peterantoine.me.uk"
] | github@peterantoine.me.uk |
504e33d6a75356632853d030cbc370d532f6bcfd | 281688f84ed2dff22db9a63abe8b90b8a485f32e | /include/E/Scheduling/E_Computer.hpp | 5b4e4e4884e72076c24feaa664c2d9e0340b3fb2 | [
"MIT"
] | permissive | Quasar0311/KENSv3 | e8136050abc5e8786dbb0f01dc61a602598271c7 | ca5c34ad9aac2feeecd49a7ba99c46e46d81eb18 | refs/heads/master | 2023-05-06T22:27:42.515868 | 2021-03-28T10:59:53 | 2021-03-28T10:59:53 | 352,297,064 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,691 | hpp | /*
* E_Computer.hpp
*
* Created on: 2014. 11. 1.
* Author: Keunhong Lee
*/
#ifndef E_COMPUTER_HPP_
#define E_COMPUTER_HPP_
#include <E/E_Common.hpp>
#include <E/E_Log.hpp>
#include <E/E_Module.hpp>
#include <E/Scheduling/E_Scheduler.hpp>
namespace E {
class Processor;
class Scheduler;
class Task;
class Job;
class Computer : public Module, private Log {
private:
UUID timerID;
bool isTimerSet;
std::vector<Processor *> cpuVector;
Scheduler *scheduler;
size_t done;
size_t miss;
size_t raised;
virtual Module::Message *messageReceived(Module *from,
Module::Message *message);
virtual void messageFinished(Module *to, Module::Message *message,
Module::Message *response);
virtual void messageCancelled(Module *to, Module::Message *message);
virtual void setTimer(Time time, void *arg) final;
virtual void cancelTimer() final;
friend void Scheduler::setTimer(Time time, void *arg);
friend void Scheduler::cancelTimer();
virtual void cancelJob(Job *job) final;
public:
Computer(System *system, CPUID numCPU, Scheduler *scheduler,
Time overhead = 0);
virtual ~Computer();
virtual void raiseJob(Task *task, Time executionTime, Time deadline) final;
CPUID getNumCPU();
size_t getDone();
size_t getMiss();
size_t getRaised();
Processor *getCPU(CPUID cpuID);
enum MessageType {
JOB_CHECK,
JOB_RUN,
TIMER,
};
class Message : public Module::Message {
public:
enum MessageType type;
union {
Job *checkingJob;
Job *runningJob;
void *arg;
};
};
};
} // namespace E
#endif /* E_COMPUTER_HPP_ */
| [
"johnking0311@gmail.com"
] | johnking0311@gmail.com |
e35fc163700d2e6f792f830bb5d31fae8f86e8d6 | c76dc04ab30acb663990aeff842436f2d4d1fcb5 | /components/scheduler/renderer/renderer_scheduler.h | e2756149da9805d332a51bafb45759932d79f595 | [
"BSD-3-Clause"
] | permissive | tongxingwy/chromium-1 | 1352c851a18a26645d69741ed6fc540fabcc862e | 9e3ebd26fa69a2e2fdf5d5f53300bbf1e2f72b8c | refs/heads/master | 2021-01-21T03:09:12.806702 | 2015-04-30T17:32:56 | 2015-04-30T17:33:35 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,597 | h | // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_
#define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_
#include "base/message_loop/message_loop.h"
#include "components/scheduler/child/child_scheduler.h"
#include "components/scheduler/child/single_thread_idle_task_runner.h"
#include "components/scheduler/scheduler_export.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace cc {
struct BeginFrameArgs;
}
namespace scheduler {
class SCHEDULER_EXPORT RendererScheduler : public ChildScheduler {
public:
~RendererScheduler() override;
static scoped_ptr<RendererScheduler> Create();
// Returns the compositor task runner.
virtual scoped_refptr<base::SingleThreadTaskRunner>
CompositorTaskRunner() = 0;
// Returns the loading task runner. This queue is intended for tasks related
// to resource dispatch, foreground HTML parsing, etc...
virtual scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() = 0;
// Returns the timer task runner. This queue is intended for DOM Timers.
virtual scoped_refptr<base::SingleThreadTaskRunner> TimerTaskRunner() = 0;
// Called to notify about the start of an extended period where no frames
// need to be drawn. Must be called from the main thread.
virtual void BeginFrameNotExpectedSoon() = 0;
// Called to notify about the start of a new frame. Must be called from the
// main thread.
virtual void WillBeginFrame(const cc::BeginFrameArgs& args) = 0;
// Called to notify that a previously begun frame was committed. Must be
// called from the main thread.
virtual void DidCommitFrameToCompositor() = 0;
// Tells the scheduler that the system received an input event. Called by the
// compositor (impl) thread.
virtual void DidReceiveInputEventOnCompositorThread(
const blink::WebInputEvent& web_input_event) = 0;
// Tells the scheduler that the system is displaying an input animation (e.g.
// a fling). Called by the compositor (impl) thread.
virtual void DidAnimateForInputOnCompositorThread() = 0;
// Tells the scheduler that all render widgets managed by this renderer
// process have been hidden. The renderer is assumed to be visible when the
// scheduler is constructed. Must be called on the main thread.
virtual void OnRendererHidden() = 0;
// Tells the scheduler that at least one render widget managed by this
// renderer process has become visible and the renderer is no longer hidden.
// The renderer is assumed to be visible when the scheduler is constructed.
// Must be called on the main thread.
virtual void OnRendererVisible() = 0;
// Returns true if the scheduler has reason to believe that high priority work
// may soon arrive on the main thread, e.g., if gesture events were observed
// recently.
// Must be called from the main thread.
virtual bool IsHighPriorityWorkAnticipated() = 0;
// Suspends the timer queue and increments the timer queue suspension count.
// May only be called from the main thread.
virtual void SuspendTimerQueue() = 0;
// Decrements the timer queue suspension count and re-enables the timer queue
// if the suspension count is zero and the current schduler policy allows it.
virtual void ResumeTimerQueue() = 0;
protected:
RendererScheduler();
DISALLOW_COPY_AND_ASSIGN(RendererScheduler);
};
} // namespace scheduler
#endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
fab54d0d2d67a09522f3430da5c1cca2fab1881d | c25ef03e084630c34d7e7354d66dd6ec457b5dd1 | /main/HyFLO1/centering.ino | 758aab35a353e1bcabf3f588469deee0fcf54cf3 | [
"Apache-2.0"
] | permissive | LinaeSostra/HyFLO1 | d764e17d17c85f00f52793463494ed9083173150 | c103c407e17ce96f160fdd42dbd41cb946a01dd3 | refs/heads/master | 2021-01-24T03:30:17.711593 | 2020-01-18T00:36:56 | 2020-01-18T00:36:56 | 122,893,056 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 4,831 | ino | /* Centering Algorithm for Containers */
// Globals
const int RIM_THRESHOLD_STEPS = 8; // Steps
const int MINIMUM_WIDTH = 45; // Steps
const int MINIMUM_CUP_HEIGHT = 10; // mm
const int RIM_DIFFERENCE = 15; // mm
const int NOZZLE_OFFSET_STEP = 4; // 100 steps = 4 mm -> 4*4mm ~ 1.6 cm
const int MAX_CENTERING_ATTEMPTS = 2;
// Variables
int rimLocation, rimLocation2 = 0;
int rimHeight, rimHeight2 = 0;
bool isFirstRimLocated, isSecondRimLocated = false;
bool hasPassedFirstRim = false;
int numOfCenteringAttempts = 0;
// Functions
void findAllRims() {
smoothReading();
// Find first rim
isFirstRimLocated = findRim(true);
// Find second rim
if(isFirstRimLocated) {
isSecondRimLocated = findRim(false);
}
#ifdef DEBUG
Serial.print("isFirstRimLocated = "); Serial.println(isFirstRimLocated);
Serial.print("isSecondRimLocated = "); Serial.println(isSecondRimLocated);
Serial.print("Steps: "); Serial.println(getStepCount());
#endif
}
bool findRim(bool isFirstRim) {
bool isRimLocated = isFirstRim ? isFirstRimLocated : isSecondRimLocated;
int height = isFirstRim ? rimHeight : rimHeight2;
int location = isFirstRim ? rimLocation : rimLocation2;
int averageHeight = getAverageHeight();
int steps = getStepCount();
if(!isRimLocated){
int hacking = 30;
bool hasPassedSketchyRegion = steps > hacking; // This sketchy region won't be an issue with the new rig.
bool isReasonableHeight = averageHeight > MINIMUM_CUP_HEIGHT;
double rimError = abs(rimHeight - averageHeight);
#ifdef DEBUG
Serial.print("Rim Height: "); Serial.println(rimHeight);
Serial.print("Average Height: "); Serial.println(averageHeight);
Serial.print("Rim Error: "); Serial.println(rimError);
#endif
if (!isFirstRim && rimError > RIM_DIFFERENCE) {
hasPassedFirstRim = true;
}
if(hasPassedSketchyRegion && isReasonableHeight) {
bool hasFoundNewRim = averageHeight > height;
if(hasFoundNewRim) {
if (isFirstRim) {
updateRimParameters(isFirstRim, averageHeight, steps);
} else {
int cupWidth = steps - rimLocation;
#ifdef DEBUG
Serial.print("Rim Difference [Rim 1, Rim2]: "); Serial.print(rimHeight); Serial.print(", "); Serial.println(averageHeight);
Serial.print("Cup Width: "); Serial.println(cupWidth);
Serial.print("Rim Error: "); Serial.println(rimError);
Serial.print("Passed First Rim?: "); Serial.println(hasPassedFirstRim);
#endif
if (rimError < RIM_DIFFERENCE && hasPassedFirstRim && cupWidth >= MINIMUM_WIDTH) {
updateRimParameters(isFirstRim, averageHeight, steps);
}
}
} else {
isRimLocated = hasRimStabilized(location);
}
}
}
return isRimLocated;
}
bool hasRimStabilized(int location) {
int rimStabilizedCounter = (location == 0) ? 0 : (getStepCount() - location);
bool hasRimStabilized = rimStabilizedCounter >= RIM_THRESHOLD_STEPS;
return hasRimStabilized ? true : false;
}
bool areAllRimsLocated() {
return isFirstRimLocated && isSecondRimLocated;
}
bool foundTwoRims() {
return rimHeight != 0 && rimHeight2 != 0;
}
void updateRimParameters(bool isFirstRim, int height, int location) {
#ifdef DEBUG
Serial.println("******************");
Serial.print("Is this the first Rim? "); Serial.println(isFirstRim);
Serial.print("newRimHeight = "); Serial.println(height);
Serial.print("newRimLocation = "); Serial.println(location);
Serial.println("******************");
#endif
if (isFirstRim) {
rimHeight = height;
rimLocation = location;
} else {
rimHeight2 = height;
rimLocation2 = location;
}
}
int calculateCenterOfContainer() {
// If failed to find both rims of the container, return 0
if (rimLocation == 0 || rimLocation2 == 0) {
return 0;
}
return ((rimLocation + rimLocation2) / 2) - NOZZLE_OFFSET_STEP - RIM_THRESHOLD_STEPS/2;
}
int calculateAverageContainerHeight() {
if(rimHeight == 0 || rimHeight2 == 0) {
return 0;
}
return ((rimHeight + rimHeight2) / 2);
}
void updateScanAttempts() {
numOfCenteringAttempts++;
#ifdef DEBUG
Serial.print("Updated numOfAttempts: ");Serial.println(numOfCenteringAttempts);
#endif
}
bool canScanAgain() {
return (numOfCenteringAttempts < MAX_CENTERING_ATTEMPTS);
}
void resetScanAttempts() {
numOfCenteringAttempts = 0;
}
void resetRimDetection() {
isFirstRimLocated = false;
isSecondRimLocated = false;
hasPassedFirstRim = false;
rimLocation = 0;
rimLocation2 = 0;
rimHeight = 0;
rimHeight2 = 0;
}
// Getter Functions
int getRimHeight() {
return rimHeight;
}
int getRim2Height() {
return rimHeight2;
}
int getRimLocation() {
return rimLocation;
}
int getRim2Location() {
return rimLocation2;
}
| [
"rebecca@dun.org"
] | rebecca@dun.org |
0459c265555277ff48386bfd079dcb063832fd65 | 9ad8ee3d13305b622f48aa3b34023b986a745669 | /positions.cpp | 6b579152ff832d874a1abb341ccf3448ee9a1d22 | [] | no_license | AndreasLeonhardt/Proj1 | e43ca59652af79ea825de3f0ff9b98d7602726c7 | ecf5005e3ca5ac13973b7d0b278114fea4c7a6ed | refs/heads/master | 2021-01-06T20:43:05.955210 | 2013-06-01T05:34:21 | 2013-06-01T05:34:21 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,957 | cpp | #include "positions.h"
positions::positions(Config * parameters)
{
ndim = parameters->lookup("ndim");
nParticles = parameters->lookup("nParticles");
r = zeros(nParticles);
rr= zeros(nParticles-1,nParticles-1);
pos=zeros(ndim,nParticles);
set_pos(randn(ndim,nParticles));
}
void positions::set_pos(mat NewPositions)
{
pos = NewPositions;
for (int i=0;i<nParticles;i++)
{
// length of position vector
r(i) = norm(pos.col(i),2);
// relative distance
for (int j=0; j<i;j++)
{
rr(i-1,j) = norm(pos.col(i)-pos.col(j),2);
}
}
}
vec positions::get_singlePos(int particleNumber)
{
return pos.col(particleNumber);
}
void positions::set_singlePos(vec NewPosition, int particleNumber)
{
// write new particle position
pos.col(particleNumber)=NewPosition;
// update r
r(particleNumber)=norm(pos.col(particleNumber),2);
// update rr
for (int j=0;j<particleNumber;j++)
{
rr(particleNumber-1,j)=norm(pos.col(particleNumber)-pos.col(j),2);
}
for (int i=particleNumber+1; i<nParticles;i++)
{
rr(i-1,particleNumber) = norm(pos.col(particleNumber)-pos.col(i),2);
}
}
void positions::step(double distance, int axis, int Particle)
{
pos(axis,Particle)+=distance;
// update r
r[Particle]=norm(pos.col(Particle),2);
// update rr
for (int j=0;j<Particle;j++)
{
rr(Particle-1,j)=norm(pos.col(Particle)-pos.col(j),2);
}
for (int i=Particle+1; i<nParticles;i++)
{
rr(i-1,Particle) = norm(pos.col(Particle)-pos.col(i),2);
}
}
double positions::get_r(int i)
{
return r[i];
}
// This functions returns the length of the differences in position between particle i and j.
// Note that r_ij has to be adressed through get_rr(i-1,j)
double positions::get_rr(int i, int j)
{
return rr(i,j);
}
mat positions::get_pos()
{
return pos;
}
| [
"andreas.leonhardt@fys.uio.no"
] | andreas.leonhardt@fys.uio.no |
739fe770fdabc54af12308164ddfdd57499e75d1 | a798ff30e5a638188bee9b48625805568c57f317 | /extern/hashlib2plus/hl_sha384wrapper.cpp | 27e9191950f7280efb5cd62e6d32711531801b35 | [
"MIT"
] | permissive | AlexanderDzhoganov/torrentstream | 390c7ae07f40176ae0cdacb64404e527d044f6f1 | afd96d51551b8b8283eb70ccbe42873a8e9e5187 | refs/heads/master | 2021-01-10T19:10:23.124490 | 2014-07-29T21:37:10 | 2014-07-29T21:37:10 | 22,107,719 | 3 | 1 | null | null | null | null | ISO-8859-3 | C++ | false | false | 3,906 | cpp | #define _CRT_SECURE_NO_WARNINGS
/*
* hashlib++ - a simple hash library for C++
*
* Copyright (c) 2007-2010 Benjamin Grüdelbach
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//----------------------------------------------------------------------
/**
* @file hl_sha384wrapper.cpp
* @brief This file contains the implementation of the sha384wrapper
* class.
* @date Mo 12 Nov 2007
*/
//----------------------------------------------------------------------
//hashlib++ includes
#include "hl_sha384wrapper.h"
//----------------------------------------------------------------------
//STL includes
#include <string>
//----------------------------------------------------------------------
//private memberfunctions
/**
* @brief This method ends the hash process
* and returns the hash as string.
*
* @return a hash as std::string
*/
std::string sha384wrapper::hashIt(void)
{
sha2_byte buff[SHA384_DIGEST_STRING_LENGTH];
sha384->SHA384_End(&context,(char*)buff);
return convToString(buff);
}
/**
* @brief This internal member-function
* convertes the hash-data to a
* std::string (HEX).
*
* @param data The hash-data to covert into HEX
* @return the converted data as std::string
*/
std::string sha384wrapper::convToString(unsigned char *data)
{
/*
* we can just copy data to a string, because
* the transforming to hash is already done
* within the sha384 implementation
*/
return std::string((const char*)data);
}
/**
* @brief This method adds the given data to the
* current hash context
*
* @param data The data to add to the current context
* @param len The length of the data to add
*/
void sha384wrapper::updateContext(unsigned char *data, unsigned int len)
{
this->sha384->SHA384_Update(&context,data,len);
}
/**
* @brief This method resets the current hash context.
* In other words: It starts a new hash process.
*/
void sha384wrapper::resetContext(void)
{
sha384->SHA384_Init(&context);
}
/**
* @brief This method should return the hash of the
* test-string "The quick brown fox jumps over the lazy
* dog"
*/
std::string sha384wrapper::getTestHash(void)
{
return "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1";
}
//----------------------------------------------------------------------
//public memberfunctions
/**
* @brief default constructor
*/
sha384wrapper::sha384wrapper()
{
this->sha384 = new SHA2ext();
}
/**
* @brief default destructor
*/
sha384wrapper::~sha384wrapper()
{
delete sha384;
}
| [
"alexander.dzhoganov@gmail.com"
] | alexander.dzhoganov@gmail.com |
32a05030271ff6ab829ae9a0376b73ba77dc0b31 | 40150c4e4199bca594fb21bded192bbc05f8c835 | /build/iOS/Preview/include/Fuse.Elements.Element.BoxSizingMode.h | a52e927c15120c04e5dd411ab20e511c41236893 | [] | no_license | thegreatyuke42/fuse-test | af0a863ab8cdc19919da11de5f3416cc81fc975f | b7e12f21d12a35d21a394703ff2040a4f3a35e00 | refs/heads/master | 2016-09-12T10:39:37.656900 | 2016-05-20T20:13:31 | 2016-05-20T20:13:31 | 58,671,009 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 366 | h | // This file was generated based on '/usr/local/share/uno/Packages/Fuse.Elements/0.27.14/$.uno#8'.
// WARNING: Changes might be lost if you edit this file directly.
#pragma once
#include <Uno.Int.h>
namespace g{
namespace Fuse{
namespace Elements{
// public enum Element.BoxSizingMode :1406
uEnumType* Element__BoxSizingMode_typeof();
}}} // ::g::Fuse::Elements
| [
"johnrbennett3@gmail.com"
] | johnrbennett3@gmail.com |
2831a5c3f744d8a8e9bf5b1bcc35aa913a2e412b | 58ccd79198beabd222a1181a6cab6428c1b33f68 | /CanonicalCover/Attribute.hpp | e455d1cb400ce58480caa98315a40584305a6e8c | [] | no_license | Thatoneguy123/Canonical-Cover | 6702d34dc0874b667482d6110ca8071a68c7078f | e6a7f7867c1f3ea63330ea48c7e927d1d77c01ae | refs/heads/master | 2021-04-26T16:43:06.581442 | 2012-05-29T15:26:42 | 2012-05-29T15:26:42 | 4,342,846 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,882 | hpp | /**
* Class implements a single attribute within a data set.
* An attribute has a single name but mutliple unique values.
*
* All values and the name are deleted upon destruction of the attribute
*/
#ifndef ATTRIBUTE_HPP
#define ATTRIBUTE_HPP
#include "stdafx.h"
#include "Instance.hpp"
namespace canonical{
class Attribute
{
private:
// Set of unique values that this attribute can have
std::set<char*>* m_values;
// The name which identifies this attribute
char* m_name;
public:
// Constructor for attribute. Takes a c string name and a pointer
// to a set of c string values. Attribute uses values that are passed in
// and will therefore invalidate any values passed in
Attribute(char* name, std::set<char*>* values);
// Deleted memort allocated for name and values for this attribute
~Attribute();
// Checks if an instances value and name are valid according to this
// particular object. If the instance is invalid the instance is simply
// returned. If the instance is valid, the instances name and value
// is deleted and replaced with the corresponding pointers from 'this'
bool isValid(Instance* instance);
// Returns a pointer to the name of this attribute
char* get_name();
// Returns a pointer to a set of c strings that are values
// for this attribute
std::set<char*>* get_values();
bool operator< (Attribute& other);
};
}
// less function for ordering in set
// Attribute will be ordered in alphabetical order by name and then values
namespace std{
template<>
struct less<canonical::Attribute*>
{
bool operator()(canonical::Attribute* a1,canonical::Attribute* a2)
{
return (*a1) < (*a2);
}
};
// Function for sorting c strings in a set. Alphabetical order
template <>
struct less<char*>
{
bool operator()(char* c1,char* c2)
{
if(strcmp(c1,c2) < 0)
return true;
else
return false;
}
};
}
#endif | [
"bagura@noctrl.edu"
] | bagura@noctrl.edu |
c551b9170bbf9a2224b024b05b1cce1508cfa492 | 006ff11fd8cfd5406c6f4318f1bafa1542095f2a | /TopQuarkAnalysis/Examples/bin/TopMuonFWLiteAnalyzer.cc | 080477532e3e4b3ed0d831bd8c71ef408aef62ba | [] | permissive | amkalsi/cmssw | 8ac5f481c7d7263741b5015381473811c59ac3b1 | ad0f69098dfbe449ca0570fbcf6fcebd6acc1154 | refs/heads/CMSSW_7_4_X | 2021-01-19T16:18:22.857382 | 2016-08-09T16:40:50 | 2016-08-09T16:40:50 | 262,608,661 | 0 | 0 | Apache-2.0 | 2020-05-09T16:10:07 | 2020-05-09T16:10:07 | null | UTF-8 | C++ | false | false | 4,265 | cc | #include <memory>
#include <string>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iostream>
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "TopQuarkAnalysis/Examples/bin/NiceStyle.cc"
#include "TopQuarkAnalysis/Examples/interface/RootSystem.h"
#include "TopQuarkAnalysis/Examples/interface/RootHistograms.h"
#include "TopQuarkAnalysis/Examples/interface/RootPostScript.h"
int main(int argc, char* argv[])
{
if( argc<3 ){
// -------------------------------------------------
std::cerr << "ERROR:: "
<< "Wrong number of arguments! Please specify:" << std::endl
<< " * filepath" << std::endl
<< " * process name" << std::endl;
// -------------------------------------------------
return -1;
}
// load framework libraries
gSystem->Load( "libFWCoreFWLite" );
AutoLibraryLoader::enable();
// set nice style for histograms
setNiceStyle();
// define some histograms
TH1I* noMuons = new TH1I("noMuons", "N(Muon)", 10, 0 , 10 );
TH1I* noLepts = new TH1I("noLepts", "N(Lepton)", 10, 0 , 10 );
TH1F* ptMuons = new TH1F("ptMuons", "pt_{Muons}", 100, 0.,300.);
TH1F* enMuons = new TH1F("enMuons", "energy_{Muons}",100, 0.,300.);
TH1F* etaMuons = new TH1F("etaMuons","eta_{Muons}", 100, -3., 3.);
TH1F* phiMuons = new TH1F("phiMuons","phi_{Muons}", 100, -5., 5.);
// -------------------------------------------------
std::cout << "open file: " << argv[1] << std::endl;
// -------------------------------------------------
TFile* inFile = TFile::Open(argv[1]);
TTree* events_= 0;
if( inFile ) inFile->GetObject("Events", events_);
if( events_==0 ){
// -------------------------------------------------
std::cerr << "ERROR:: "
<< "Unable to retrieve TTree Events!" << std::endl
<< " Eighter wrong file name or the the tree doesn't exists" << std::endl;
// -------------------------------------------------
return -1;
}
// acess branch of muons and elecs
char muonName[50];
sprintf(muonName, "patMuons_selectedPatMuons__%s.obj", argv[2]);
TBranch* muons_ = events_->GetBranch( muonName ); assert( muons_!=0 );
char elecName[50];
sprintf(elecName, "patElectrons_selectedPatElectrons__%s.obj", argv[2]);
TBranch* elecs_ = events_->GetBranch( elecName ); assert( elecs_!=0 );
// loop over events and fill histograms
std::vector<pat::Muon> muons;
std::vector<pat::Electron> elecs;
int nevt = events_->GetEntries();
// -------------------------------------------------
std::cout << "start looping " << nevt << " events..." << std::endl;
// -------------------------------------------------
for(int evt=0; evt<nevt; ++evt){
// set branch address
muons_->SetAddress( &muons );
elecs_->SetAddress( &elecs );
// get event
muons_ ->GetEntry( evt );
elecs_ ->GetEntry( evt );
events_->GetEntry( evt, 0 );
// -------------------------------------------------
if(evt>0 && !(evt%10)) std::cout << " processing event: " << evt << std::endl;
// -------------------------------------------------
// fill histograms
noMuons->Fill(muons.size());
noLepts->Fill(muons.size()+elecs.size());
for(unsigned idx=0; idx<muons.size(); ++idx){
// fill histograms
ptMuons ->Fill(muons[idx].pt() );
enMuons ->Fill(muons[idx].energy());
etaMuons->Fill(muons[idx].eta() );
phiMuons->Fill(muons[idx].phi() );
}
}
// -------------------------------------------------
std::cout << "close file" << std::endl;
// -------------------------------------------------
inFile->Close();
// save histograms to file
TFile outFile( "analyzeMuons.root", "recreate" );
outFile.mkdir("analyzeMuon");
outFile.cd("analyzeMuon");
noMuons ->Write( );
noLepts ->Write( );
ptMuons ->Write( );
enMuons ->Write( );
etaMuons->Write( );
phiMuons->Write( );
outFile.Close();
// free allocated space
delete noMuons;
delete noLepts;
delete ptMuons;
delete enMuons;
delete etaMuons;
delete phiMuons;
return 0;
}
| [
"giulio.eulisse@gmail.com"
] | giulio.eulisse@gmail.com |
1f7792e48db4444f2e64492578e778553b6bb436 | 9d9c27c5fe52838bed8c6ea9d7c2ad7ae997a54a | /Library/Cegui/cegui/include/CEGUI/ImageCodec.h | fd20ba907dd910947232aacbc0a9183af7d2cf66 | [] | no_license | respu/xsilium-engine | f19fe3ea41fb8d8b2010c225bf3cadc2b31ce5e8 | 36a282616c055b24c44882c8f219ba72eec269c7 | refs/heads/master | 2021-01-15T17:36:51.212274 | 2013-06-07T07:20:54 | 2013-06-07T07:20:54 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,568 | h | /***********************************************************************
filename: CEGUIImageCodec.h
created: 03/06/2006
author: Olivier Delannoy
purpose: Define the abstract interface for all common ImageCodec
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#ifndef _CEGUIImageCodec_h_
#define _CEGUIImageCodec_h_
#include "CEGUI/Base.h"
#include "CEGUI/DataContainer.h"
#include "CEGUI/Texture.h"
// Start of CEGUI namespace section
namespace CEGUI
{
/*!
\brief
Abstract ImageLoader class. An image loader encapsulate the loading of a texture.
This class define the loading of an abstract
*/
class CEGUIEXPORT ImageCodec :
public AllocatedObject<ImageCodec>
{
public:
/*!
\brief
Destructor
*/
virtual ~ImageCodec();
protected:
/*
\brief
Constructor
\param name of the codec
*/
ImageCodec(const String& name);
public:
/*!
\brief
Return the name of the image codec object
Return the name of the image codec
\return a string containing image codec name
*/
const String& getIdentifierString() const;
/*!
\brief
Return the list of image file format supported
Return a list of space separated image format supported by this
codec
\return
list of supported image file format separated with space
*/
const String& getSupportedFormat() const;
/*!
\brief
Load an image from a memory buffer
\param data the image data
\param result the texture to use for storing the image data
\return result on success or 0 if the load failed
*/
virtual Texture* load(const RawDataContainer& data, Texture* result) = 0;
private:
String d_identifierString; //!< display the name of the codec
protected:
String d_supportedFormat; //!< list all image file format supported
private:
ImageCodec(const ImageCodec& obj);
ImageCodec& operator=(ImageCodec& obj);
};
} // End of CEGUI namespace section
#endif // end of guard _CEGUIImageCodec_h_
| [
"xelfes@gmail.com"
] | xelfes@gmail.com |
9485d644c043ad45524b3c79fe71e2708a3722f0 | fed4f159d1718e94fbf1b831b9827139ef735cd4 | /readfile/Pcap.cpp | e869aa5354ddfd55b744bf485d5130fd057fdbb8 | [] | no_license | breaniac/libpcapWin10x64_MakeAll | 03df3db3e491d1feedd80efc4a74c659e398abc8 | 1293c2ff6b42266a765e82f88567701f87c98fb4 | refs/heads/master | 2023-04-21T20:07:16.969989 | 2021-05-12T17:54:09 | 2021-05-12T17:54:09 | 350,067,225 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,823 | cpp | #include "Pcap.h"
#include "stun_t.h"
#include "rtp_t.h"
#include <string.h>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
using namespace stun;
using namespace rtp;
Pcap::Pcap()
{
memset(&m_nextRes, 0, sizeof(m_nextRes));
packetCount = 0;
}
Pcap::~Pcap()
{
packetCount = 0;
}
bool Pcap::init(const char *fname)
{
p_Cap = pcap_open_offline(fname, errbuf);
if (!p_Cap) return false;
return true;
}
void Pcap::operator ++()
{
/////m_nextRes.data = pcap_next(p_Cap, &m_nextRes.out);
m_nextRes.data = pcap_next(adhandle, &m_nextRes.out);
#ifdef _DEBUG
//#else
//struct pcap_pkthdr* out;
////while (int returnValue = pcap_next_ex(p_Cap, &out, &m_nextRes.data) >= 0)
//while (int returnValue = pcap_next_ex(adhandle, &out, &m_nextRes.data) >= 0)
//{
// // Print using printf. See printf reference:
// // http://www.cplusplus.com/reference/clibrary/cstdio/printf/
// // Show the packet number
// printf("Packet # %i\n", ++packetCount);
// // Show the size in bytes of the packet
// printf("Packet size: %ld bytes\n", out->len);
// // Show a warning if the length captured is different
// if (out->len != out->caplen)
// printf("Warning! Capture size different than packet size: %ld bytes\n", out->len);
// // Show Epoch Time
// printf("Epoch Time: %ld:%ld seconds\n", out->ts.tv_sec, out->ts.tv_usec);
// // loop through the packet and print it as hexidecimal representations of octets
// // We also have a function that does this similarly below: PrintData()
// for (u_int i = 0; (i < out->caplen); i++)
// {
// // Start printing on the next after every 16 octets
// if ((i % 256) == 0) printf("\n");
// // Print each octet as hex (x), make sure there is always two characters (.2).
// printf("%c", m_nextRes.data[i]); //"%.2x "
// }
// // Add two lines between packets
// printf("\n\n");
//}
#endif
}
Result_t& Pcap::next()
{
operator++();
return m_nextRes;
}
bool Pcap::hasNext() const
{
if (DUMP_PAKETS == packetCount)
{
packetCount = 0;
return false;
}
return true;
//return m_nextRes.data != nullptr;
}
/**
* @brief Pcap::loop - example loop of packets...
*/
void Pcap::loop()
{
//for(Result_t& res = next(); hasNext(); operator++())
while (1)
{
for (Result_t& res = next(); hasNext(); operator++())
{
auto resultNwork = VParse(StunRFC{ res },
RtpRFC{ res });
(void)resultNwork;
}
std::ofstream jsonfile;
jsonfile.open("out.json");
jsonfile << serializer.serialize();
jsonfile.close();
}
}
| [
"sergeirmichailov@gmail.com"
] | sergeirmichailov@gmail.com |
395a6ff157cfa3ff9f473d515307da854084727e | bca5c1977979fc0fbf3d8c2a4020ab95c5222d45 | /hid.cpp | cd25f05810861f0c70d331c3381bde90bb643fe2 | [] | no_license | VladimirP1/imuhost_wip | efaf13f3363ad1c52086227fb2c7fcfd16d1f6c7 | ca8ad03fcb15790900700550a2a709402abec0de | refs/heads/master | 2020-03-23T16:33:34.791326 | 2018-07-21T13:52:47 | 2018-07-21T13:52:47 | 141,817,433 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,942 | cpp | #include "hid.h"
#include <hidapi.h>
HID::HID()
{
if (hid_init()) {
throw HID_exception("Could not init HIDAPI");
}
}
HID::~HID()
{
hid_exit();
}
void HID::open(uint16_t pid, uint16_t vid) {
if(dev_handle) {
throw HID_exception("Already open");
}
dev_handle = hid_open(pid, vid, NULL);
if(!dev_handle) {
throw HID_exception("Could not open device");
}
}
int HID::read(gsl::span<uint8_t> data) {
if(!dev_handle) {
throw HID_exception("Attempt an operation on a closed device");
}
int res = hid_read_timeout(dev_handle, &data[0], data.size(), 1000);
if(res < 0) {
throw HID_exception("Read error");
}
return res;
}
int HID::write(gsl::span<uint8_t> data) {
if(!dev_handle) {
throw HID_exception("Attempt an operation on a closed device");
}
int res = hid_write(dev_handle, &data[0], data.size());
if(res < 0) {
throw HID_exception("Write error");
}
return res;
}
int HID::set_feature(gsl::span<uint8_t> data) {
if(!dev_handle) {
throw HID_exception("Attempt an operation on a closed device");
}
int res = hid_send_feature_report(dev_handle, &data[0], data.size());
if(res < 0) {
throw HID_exception("Read error");
}
return res;
}
int HID::get_feature(gsl::span<uint8_t> data) {
if(!dev_handle) {
throw HID_exception("Attempt an operation on a closed device");
}
int res = hid_get_feature_report(dev_handle, &data[0], data.size());
if(res < 0) {
throw HID_exception("Write error");
}
return res;
}
void HID::set_nonblocking(bool is_nonblock) {
if(!dev_handle) {
throw HID_exception("Attempt an operation on a closed device");
}
hid_set_nonblocking(dev_handle, is_nonblock);
}
void HID::close(){
if(!dev_handle) {
throw HID_exception("Already closed");
}
hid_close(dev_handle);
}
| [
"vladimir.pinchuk01@gmail.com"
] | vladimir.pinchuk01@gmail.com |
c5e51b2dd6f54b838e5796187b290a4275e28502 | ea2cc666f3bc292435bb9a2dbe2326cf9a85f123 | /Phoenix3D/PX2Mathematics/PX2BSplineVolume.hpp | 1c14a6538bec003a0aac1b0e2d36595f8bb3196d | [] | no_license | libla/Phoenix3D | c030b9b3933623dd58826f18754aaddf557575c0 | 788a04f922f38a12dc7886fe686a000785443f95 | refs/heads/master | 2020-12-06T19:12:36.116291 | 2015-07-27T16:14:57 | 2015-07-27T16:14:57 | 39,821,992 | 1 | 1 | null | 2015-07-28T08:24:41 | 2015-07-28T08:24:40 | null | UTF-8 | C++ | false | false | 1,895 | hpp | // PX2BSplineVolume.hpp
#ifndef PX2BSPLINEVOLUME_HPP
#define PX2BSPLINEVOLUME_HPP
#include "PX2MathematicsPre.hpp"
#include "PX2BSplineBasis.hpp"
#include "PX2Vector3.hpp"
namespace PX2
{
template <typename Real>
class PX2_MATHEMATICS_ITEM BSplineVolume
{
public:
// Construction and destruction of an open uniform B-spline volume. The
// class will allocate space for the control points. The caller is
// responsible for setting the values with the member function
// ControlPoint.
BSplineVolume (int numUCtrlPoints, int numVCtrlPoints,
int numWCtrlPoints, int uDegree, int vDegree, int wDegree);
~BSplineVolume ();
int GetNumCtrlPoints (int dim) const;
int GetDegree (int dim) const;
// Control points may be changed at any time. If any input index is
// invalid, the returned point is a vector whose components are all
// MAX_REAL.
void SetControlPoint (int uIndex, int vIndex, int wIndex,
const Vector3<Real>& ctrlPoint);
Vector3<Real> GetControlPoint (int uIndex, int vIndex, int wIndex) const;
// The spline is defined for 0 <= u <= 1, 0 <= v <= 1, and 0 <= w <= 1.
// The input values should be in this domain. Any inputs smaller than 0
// are clamped to 0. Any inputs larger than 1 are clamped to 1.
Vector3<Real> GetPosition (Real u, Real v, Real w) const;
Vector3<Real> GetDerivativeU (Real u, Real v, Real w) const;
Vector3<Real> GetDerivativeV (Real u, Real v, Real w) const;
Vector3<Real> GetDerivativeW (Real u, Real v, Real w) const;
// for array indexing: i = 0 for u, i = 1 for v, i = 2 for w
Vector3<Real> GetPosition (Real pos[3]) const;
Vector3<Real> GetDerivative (int i, Real pos[3]) const;
private:
Vector3<Real>*** mCtrlPoint; // ctrl[unum][vnum][wnum]
BSplineBasis<Real> mBasis[3];
};
typedef BSplineVolume<float> BSplineVolumef;
typedef BSplineVolume<double> BSplineVolumed;
}
#endif
| [
"realmany@163.com"
] | realmany@163.com |
35f0204a54a0dd571ba3180cd27282c82b992efc | 6f91f5b8b663c9bd349bbc150874858fcc39f5b9 | /qtgui/mainwindow.h | 8cba24816a8345461c4ad7792d43503d530eb3f5 | [
"BSL-1.0",
"BSD-2-Clause"
] | permissive | dfuhry/denali | 2ecfb76dfc4c4b29839e5e211f9cc72e1501f53a | a82f1db916e1cae70da0dc30d7c60342931f4a9c | refs/heads/master | 2020-12-24T21:37:33.435332 | 2015-02-09T23:14:18 | 2015-02-09T23:14:18 | 30,563,332 | 0 | 0 | null | 2015-02-09T22:56:38 | 2015-02-09T22:56:37 | null | UTF-8 | C++ | false | false | 4,616 | h | // Copyright (c) 2014, Justin Eldridge, Mikhail Belkin, and Yusu Wang
// at The Ohio State University. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef DENALI_QTGUI_MAINWINDOW_H
#define DENALI_QTGUI_MAINWINDOW_H
#include <boost/shared_ptr.hpp>
#include <QMainWindow>
#include <QtGui>
#include "colormapdialog.h"
#include "callbacksdialog.h"
#include "chooserootdialog.h"
#include "ui_MainWindow.h"
#include "landscape_context.h"
#include "landscape_interface.h"
class MainWindow : public QMainWindow, public LandscapeEventObserver
{
Q_OBJECT
public:
MainWindow();
void setContext(LandscapeContext*);
void receiveCellSelection(unsigned int);
std::string prepareCallback(std::string callback_path,
unsigned int cell,
QTemporaryFile& tempfile,
bool provide_subtree = false);
std::string runSynchronousCallback(std::string callback_path,
unsigned int cell,
bool provide_subtree = false);
void runAsynchronousCallback(std::string callback_path,
unsigned int cell,
bool provide_subtree = false);
public slots:
void setStatus(const std::string&);
void appendStatus(const std::string&);
void openContourTreeFile();
void renderLandscape();
void changeLandscapeRoot();
void updateCellSelection(unsigned int);
void enablePersistenceSlider();
void updatePersistence(int);
void enableRefineSubtree();
void disableRefineSubtree();
void refineSubtree();
void enableLoadWeightMap();
void enableClearWeightMap();
void disableClearWeightMap();
void loadWeightMapFile();
void clearWeightMap();
void enableConfigureColorMap();
void enableClearColorMap();
void disableClearColorMap();
void configureColorMap();
void clearColorMap();
void configureCallbacks();
void runInfoCallback();
void runTreeCallback();
void runAsyncCallback();
void updateCallbackAvailability();
void runCallbacksOnSelection();
void enableInfoCallback();
void enableTreeCallback();
void enableAsyncCallback();
void disableInfoCallback();
void disableTreeCallback();
void disableAsyncCallback();
void enableRebaseLandscape();
void disableRebaseLandscape();
void rebaseLandscape();
void enableExpandLandscape();
void disableExpandLandscape();
void expandLandscape();
void enableChooseRoot();
void chooseRoot();
signals:
void landscapeChanged();
void cellSelected(unsigned int);
private:
Ui::MainWindow _mainwindow;
boost::shared_ptr<LandscapeContext> _landscape_context;
boost::shared_ptr<LandscapeInterface> _landscape_interface;
int _max_persistence_slider_value;
unsigned int _cell_selection;
ColorMapDialog* _color_map_dialog;
CallbacksDialog* _callbacks_dialog;
ChooseRootDialog* _choose_root_dialog;
bool _use_color_map;
std::string _filename;
enum SelectedReduction
{
MAXIMUM,
MINIMUM,
MEAN,
COUNT,
VARIANCE,
COVARIANCE,
CORRELATION
};
int _progress_wait_time;
};
#endif
| [
"eldridgejm@gmail.com"
] | eldridgejm@gmail.com |
d0a8fa00fc059684af4b5a4d8420d235bc09009e | aa1c174ac1637f761f32659512d9cbcd11ca187b | /imp/heuristics/beginnings/allpairs_fpairs.cpp | cd2b108cb12d300b5cbed6b6965fe1ccd0c914c4 | [] | no_license | cvalentim/dissertation | 421c45cdfcd2c2c459b295f80343366fe07a9816 | eb64b1e5eea3bdcaf03e061b06a54870eb5182f5 | refs/heads/master | 2020-04-15T01:48:22.946681 | 2012-06-27T03:58:25 | 2012-06-27T03:58:25 | 2,806,505 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,110 | cpp | #ifndef __BEG_ALLPAIRS_FPAIRS__
#define __BEG_ALLPAIRS_FPAIRS__
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
#include "range_list/range_list.cpp"
#include "../../../../rmq/cpp/rmq_bucket.cpp"
#include "../heuristic.cpp"
//#include "../allpairs/h_fpairs.cpp"
#include "../allpairs/specialPairsH.cpp"
using namespace std;
template<class T>
class AllPairsFPairs: public Heuristic<T>
{
HFPairs<T> *h_all;
RangeList<T> *h_beg;
int n;
public:
AllPairsFPairs(){
h_all = new HFPairs<T>();
h_beg = new RangeList<T>();
}
~AllPairsFPairs(){
delete h_all;
delete h_beg;
}
int get_presize(){
return 42;
}
string get_name(){
return "Beg-Hybrid";
}
void preprocess(vector<T>& A){
n = (int) A.size();
h_all->preprocess(A);
h_beg->light_preprocess(A);
}
// <= t and >= d
// the pair (a_i, a_j) has distance of j - i and size a_j - a_i
long long query(int delta_t, T delta_v){
vector<int> ends = h_all->genSpecialEnds(delta_t, delta_v);
return h_beg->BegByEnd(ends, delta_t, delta_v).size();
}
};
#endif
| [
"kakaio9@gmail.com"
] | kakaio9@gmail.com |
9ddee52ed4ec63239ea48cc3bfe7df139808f5c2 | fb9f9bf18726250513c88f18126c8e691f87796e | /fullyconnectednet/fullyconnectednet.hh | 0cf47f33ac66829bf07026e00437188138af9450 | [] | no_license | ConnorStone628/NeuralNet | 59a3810336e7da9bd19937637bb579000227648f | 825e808ae22977c0db744e79979a00e82f18af9b | refs/heads/master | 2021-01-10T17:39:41.888825 | 2016-02-03T16:40:57 | 2016-02-03T16:40:57 | 49,081,136 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,111 | hh | #ifndef __FULLYCONNECTEDNET__
#define __FULLYCONNECTEDNET__
#include "../basenet/net.hh"
class fullyconnectednet : public net {
protected:
// Scaling parameter for weight updates
double learning_rate;
// Calculate activation rates on all nodes
void Rates();
// Calculate error along the top row
void TopErrors(std::vector<double> true_values);
// Back-Propogate errors through the net
void BackPropogateErrors();
public:
// Constructor
fullyconnectednet(std::vector<unsigned int> nodes_per_layer, double (*activation_function)(double), double (*activation_derivative)(double));
// Destructor
~fullyconnectednet();
// Set the constant factor that weight updates are scaled by
void SetLearningRate(double rate);
// Gradient descent backpropogation to learn weights
void BackPropogate(std::vector<double> true_values);
// Override net Input function so that input is not written to the bias node at that level
void Input(std::vector<double> input_values);
// Override net ClearInputs so that bias nodes are not cleared
void ClearInputs();
};
#endif
| [
"connor_mc2@hotmail.com"
] | connor_mc2@hotmail.com |
290927a7eab0ec5e1686f7223ae856b5aee8f275 | cf2fc63b570c23eb26b7cc1742bbabcbe978721c | /cs165/assign07/smallAsteroid.h | 5afb66aa301b18b9324574ed66b418c1c1a52adf | [] | no_license | mahoryu/School_FIles | 77175203cf2b18d4eb8e7a168c760936e0a036b0 | afcc73957c24e73289cb960de6196eb1102786d8 | refs/heads/master | 2022-01-09T20:21:03.666621 | 2019-04-30T02:40:52 | 2019-04-30T02:40:52 | 183,820,851 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 870 | h | /*************************************************************
* File: smallAsteroid.h
* Author: Ethan Holden
*
* Description: Contains the definition of the smallAsteroid
* class.
*************************************************************/
#ifndef SMALLASTEROID_H
#define SMALLASTEROID_H
#include "point.h"
#include "velocity.h"
class SmallAsteroid
{
private:
Point point;
Velocity velocity;
float gravity;
bool alive;
public:
SmallAsteroid();
Point getPoint() const {return point;}
Velocity getVelocity() const {return velocity;}
bool isAlive() {return alive;}
void setVelocity(Velocity velocity) {this->velocity = velocity;}
void setPoint(Point point) {this->point = point;}
void setAlive(bool alive) {this->alive = alive;}
void applyGravity(float gravity);
void advance();
void draw();
};
#endif
| [
"noreply@github.com"
] | noreply@github.com |
121d3b3f70e45204b378ad2e9d063de563772ffa | 0d3dc52ab0c1ccef8fde4b36e2b74ab79b8a3402 | /source/Insider/PhoenixThread.hpp | 56e1c1cd222292a5bde1d55759218feb36fac8e2 | [
"MIT"
] | permissive | Crasader/Phoenix | c560c20ce3f51911bb67e0c17c2bb6f83c42c973 | 28a7c6a3932fd7d6fea12770d0aa1e20bc70db7d | refs/heads/master | 2021-02-27T15:55:20.093687 | 2018-05-05T13:07:36 | 2018-05-05T13:07:36 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 873 | hpp | /*********************************************************************************************************
* PhoenixThread.hpp
* Note: Phoenix Thread
* Date: 2015.01
* E-mail:<forcemz@outlook.com>
* Copyright (C) 2015 The ForceStudio All Rights Reserved.
**********************************************************************************************************/
#ifndef PHOENIX_THREAD_HPP
#define PHOENIX_THREAD_HPP
#include <Windows.h>
#include <functional>
typedef DWORD (WINAPI *ThreadCallBack)(LPVOID lpThreadParameter);
class PhoenixThread{
private:
DWORD IdOfThread;
LPVOID m_param;
HANDLE hThread;
bool IsRunOnce;
ThreadCallBack m_eFunc;
public:
PhoenixThread(ThreadCallBack efunc,LPVOID param);
unsigned GetThreadObjectId(){return this->IdOfThread;}
bool Run();
bool Suspend();
bool Resume();
bool Exit();
};
#endif
| [
"fvstudio@outlook.com"
] | fvstudio@outlook.com |
de4d89ee1fc57a9a7727160566f96726fe8c1015 | 67240d96eac9eac2d971ddc396d8ed68b17fa6fb | /neo_c_lib/src/TempPF.cpp | a9727fb8fce6128c6ef6a84fd0f6c1adbb9806b8 | [] | no_license | neo1seok/neolib_c_base | f80010681dbf56f06f00c5b0244c753771923530 | dd430793ad628f0659e26b50702d9d0c298217cb | refs/heads/master | 2021-03-19T18:31:15.855617 | 2018-08-27T00:51:38 | 2018-08-27T00:51:38 | 120,698,140 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,442 | cpp |
#include <iostream>
#include <map>
#include "rs232.h"
#include "Util.h"
#include "CtrlBASE.h"
#include "CtrlECC.h"
#include "CtrlRSA.h"
#include "commfunc.h"
#include "neoCoLib.h"
#ifndef _WIN32
#include <sys/time.h>
#endif
/*
CMD_REQ_TEST
CMD_ERR_TEST
CMD_REQ_SEL_PUF
CMD_REQ_CONFIG
CMD_REQ_SN
CMD_REQ_EHK
CMD_REQ_SIGN
CMD_REQ_PUK_ECC
CMD_REQ_REG_CERT_ECC
CMD_REQ_AUTH_ECC
CMD_REQ_HS1_ECC
CMD_ERR_HS2_ECC
CMD_REQ_ID_RSA
CMD_REQ_PUK_RSA
CMD_REQ_CERT_RSA
CMD_REQ_REG_CERT_RSA
CMD_REQ_AUTH_RSA
CMD_REQ_SESSION_RSA
CMD_REQ_HS1_RSA
CMD_RES_SIGN_RSA
CMD_REQ_CTR
CMD_REQ_ENC_CCM
CMD_REQ_HMAC
CMD_REQ_CRYPTO_CONT
CMD_REQ_HMAC_CONT
CMD_REQ_CCM_GENERATE_MAC
CMD_REQ_GENERATE_HMAC
CMD_REQ_DEC_CCM
CMD_REQ_CCM_VERIFY_MAC
CMD_REQ_VERIFY_HMAC
*/
#if 0
#define FUNCGENDEF(cmd_) void tmp_gen##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlBASE*pThis, void* param){ pThis->gen##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#define FUNCPOSTDEF(cmd_) void tmp_postProc##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlBASE*pThis, void* param){ pThis->postProc##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#define FUNCGENDEF_ECC(cmd_) void tmp_gen##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlECC*pThis, void* param){ pThis->gen##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#define FUNCPOSTDEF_ECC(cmd_) void tmp_postProc##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlECC*pThis, void* param){ pThis->postProc##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#define FUNCGENDEF_RSA(cmd_) void tmp_gen##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlRSA*pThis, void* param){ pThis->gen##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#define FUNCPOSTDEF_RSA(cmd_) void tmp_postProc##cmd_(int cmd, BYTE * pbuff, int & size, std::string &strlog, CCtrlRSA*pThis, void* param){ pThis->postProc##cmd_(cmd, pbuff, size, strlog, pThis,param);}
#endif
FUNCDEF(gen, CCtrlBASE, DefCMD);
FUNCDEF(gen, CCtrlBASE, ErrCMD);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_TEST);
FUNCDEF(gen, CCtrlBASE, CMD_ERR_TEST);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_SEL_PUF);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_CONFIG);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_SN);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_EHK);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_SIGN);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_CTR);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_ENC_CCM);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_HMAC);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_CRYPTO_CONT);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_HMAC_CONT);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_CCM_GENERATE_MAC);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_GENERATE_HMAC);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_DEC_CCM);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_CCM_VERIFY_MAC);
FUNCDEF(gen, CCtrlBASE, CMD_REQ_VERIFY_HMAC);
FUNCDEF(postProc, CCtrlBASE, DefCMD);
//FUNCDEF(postProc, CCtrlBASE, ErrCMD);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_TEST);
FUNCDEF(postProc, CCtrlBASE, CMD_ERR_TEST);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_SEL_PUF);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_CONFIG);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_SN);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_EHK);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_SIGN);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_CTR);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_ENC_CCM);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_HMAC);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_CRYPTO_CONT);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_HMAC_CONT);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_CCM_GENERATE_MAC);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_GENERATE_HMAC);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_DEC_CCM);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_CCM_VERIFY_MAC);
FUNCDEF(postProc, CCtrlBASE, CMD_REQ_VERIFY_HMAC);
FUNCDEF(gen, CCtrlECC, CMD_REQ_PUK_ECC);
FUNCDEF(gen, CCtrlECC, CMD_REQ_REG_CERT_ECC);
FUNCDEF(gen, CCtrlECC, CMD_REQ_AUTH_ECC);
FUNCDEF(gen, CCtrlECC, CMD_REQ_HS1_ECC);
FUNCDEF(gen, CCtrlECC, CMD_ERR_HS2_ECC);
FUNCDEF(postProc, CCtrlECC, CMD_REQ_PUK_ECC);
FUNCDEF(postProc, CCtrlECC, CMD_REQ_REG_CERT_ECC);
FUNCDEF(postProc, CCtrlECC, CMD_REQ_AUTH_ECC);
FUNCDEF(postProc, CCtrlECC, CMD_REQ_HS1_ECC);
FUNCDEF(postProc, CCtrlECC, CMD_ERR_HS2_ECC);
FUNCDEF(gen, CCtrlRSA, CMD_REQ_PUK_RSA);
FUNCDEF(gen, CCtrlRSA, CMD_REQ_REG_CERT_RSA);
FUNCDEF(gen, CCtrlRSA, CMD_REQ_AUTH_RSA);
FUNCDEF(gen, CCtrlRSA, CMD_REQ_HS1_RSA);
FUNCDEF(postProc, CCtrlRSA, CMD_REQ_PUK_RSA);
FUNCDEF(postProc, CCtrlRSA, CMD_REQ_REG_CERT_RSA);
FUNCDEF(postProc, CCtrlRSA, CMD_REQ_AUTH_RSA);
FUNCDEF(postProc, CCtrlRSA, CMD_REQ_HS1_RSA);
| [
"neo1seok@gmail.com"
] | neo1seok@gmail.com |
43ee7267846cc24835ce16a0ceb2c8b670b11a85 | 83ed4ea876b3c6299c58683127db8f88224f110d | /UAS Kelompok 2.cxx | c2b0be494a58ca35644854cd94e9b68edddf7eb5 | [] | no_license | Nearzs/UAS-Kelompok-2 | fd8329ec0a01a71a6a3765bb0be96bcee90d1b48 | c2c0b34df92d3628afe99f5fb314351991c19adb | refs/heads/master | 2020-06-25T17:27:09.899289 | 2019-07-29T04:32:12 | 2019-07-29T04:32:12 | 199,377,379 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,122 | cxx | #include<conio.h>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
struct data{
char nama[30];
int kode, stok;
};
data batas[100];
int a,b,c,d;
void garis(){
cout<<"===============================================================================\n";}
void urut(int a , data batas[30]){
for(int i=0;i<a;i++)
{
data tp;
for(int j = i+1;j < a ;j++ ){
for(int l=0 ; l < 30 ;l++){
if(batas[i].nama[l] < batas[j].nama[l]){
break ;
}else if(batas[i].nama[l] > batas[j].nama[l]){
tp=batas[i];
batas[i] = batas[j];
batas[j] = tp;
break;
}
}
}
}
}
void inputdata()
{ cout<<"\nJumlah Barang Yang Akan diinput : ";cin>>b;
for(c=0;c<b;c++){
cout<<"\nData ke-"<<c+1<<endl;
cout<<"Kode Barang\t: " ;cin>>batas[a].kode;
cout<<"Nama Barang\t: ";cin>>batas[a].nama;
cout<<"Jumlah Barang\t: ";cin>>batas[a].stok;
a++;}system("cls");}
void lihatdata()
{int i;
garis();
cout<<"================================Menampilkan Data===============================\n";
garis();
/*
cout<<"|NO"<<setw(9)<<"|"<<setw(10)<<"Kode Barang"<<setw(9)<<"|"<<setw(9)<<"Nama Barang"<<setw(18)<<"|"<<setw(9)<<"Jumlah Barang"<<setw(6)<<"|\n";
*/
garis();
urut(a,batas);
for ( i = 0; i <a ;i++){
cout<<"|"<<i+1<<setw(10)<<"|"<<setw(10)<<batas[i].kode<<setw(10)<<"|"<<setw(10)<<batas[i].nama<<setw(19)<<"|"<<setw(10)<<batas[i].stok<<setw(8)<<"|\n";
}
garis();
}
void hapusdata()
{int x;
cout<<"Hapus data ke-";cin>>x;
if (x<=b){
a--;
for(int i=x-1;i<a;i++)
{batas[i]=batas[i+1];}
system("cls");
cout<<"\n\n\n\n\n\n\n\n\n++++++++++++++++++++++++++++++ Data ke-"<<x<<" Terhapus ++++++++++++++++++++++++++++++";
getch();system("cls");}else{cout<<"data tidak ditemukan!!!";getch();system("cls");}
}
void editdata(){
int k,l;
cout<<"Masukan Data yang akan diedit : ";cin>>k;
l=k-1;
c=b+1;
if (k<c){
cout<<"Kode Barang\t: ";cin>>batas[l].kode;
cout<<"Nama Barang\t: ";cin>>batas[l].nama;
cout<<"Jumlah Barang\t: ";cin>>batas[l].stok;
lihatdata();}
else {system("cls");
cout<<"\n\n\n\n\n\n\n\n\n++++++++++++++++++++++++++++++ Erorr !!! Data ke-"<<k<<" Tidak Tersedia ++++++++++++++++++++++++++++++";}
getch();system("cls");
}
void atas(){
char user[20], pass[4];
cout<<" Silakan Login terlebih dahulu \n";
cout<<" Username : "; cin>>user;
if(strcmp(user,"kelompok2")==0) {
cout<<" User Berhasil Login\n";
garis();
cout<<endl;
system("cls");
}else{cout<< "User Tidak Ada\n";
atas();
}
cout<<" Password : "; cin>>pass;
if(strcmp(pass,"12345")==0) {
cout<<" User Berhasil Login\n";
garis();
cout<<endl;
system("cls");
}else{cout<< "Password Salah\n";
atas();
}
}
int main()
{ int pilih;
char w;
garis();
cout<<" \t\t Aplikasi Inventory Barang Kelompok 2 \n";
garis();
cout<<endl;
atas();
awal:
garis();
cout<<"================================ PILIHAN MENU =================================\n";
garis();
cout<<"\n1. Buat Data Barang";
cout<<"\n2. Hapus Data Barang";
cout<<"\n3. Lihat Data Barang";
cout<<"\n4. Edit Data Barang";
cout<<"\n5. Keluar";
cout<<"\n\nMasukkan Pilihan : ";
cin>>pilih;
if(pilih==1)
{system("cls");inputdata();goto awal;}
if(pilih==2)
{system("cls");hapusdata();goto awal;}
if(pilih==3)
{system("cls");lihatdata();goto awal;}
if(pilih==4)
{system("cls");editdata();goto awal;}
if(pilih==5)
{system("cls");
cout<<"\n\n\n\n\n\n\n\n APAKAH ANDA YAKIN KELUAR DARI PROGRAM??\n\n";
cout<<" [Y] [N] \n"<<endl;
cout<<" ";cin>>w;
if(w=='y'||w=='Y')
{system("cls");
cout<<"\n\n\n\n\n******************************* PROGRAM SELESAI *******************************";}
if(w=='n'||w=='N')
{system("cls");goto awal;}}
else
{system("cls");cout<<" Pilihan tidak tersedia!!!\n";getch();system("cls");goto awal;}
}
| [
"noreply@github.com"
] | noreply@github.com |
dfcc85e3b2496cd3c78fb7f0167150c95144a5f7 | ad82edc8ff11e596d2129f85333817061f99d5d5 | /Cpp_Primer_5E_Learning/Chapter10/E10.33.cpp | f2d336ec25b72337e8836e32668fd46537fd2006 | [
"MIT"
] | permissive | feiwofeifeixiaowo/CppPrimer5thAnswer | d8597e8b1bfc42309fa53c8b11d56e06854dd747 | c22fb5f9369d05cafb7f3d8d75b4f499de4c2105 | refs/heads/master | 2021-05-01T05:34:18.643823 | 2016-12-16T08:51:11 | 2016-12-16T08:51:11 | 70,390,235 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 854 | cpp | //
// Created by Xiyun on 2016/10/23.
//
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void someMethod(string input_filename,string odd_filename,string even_filename)
{
//没必要缓存下来
// vector<int> vec;
ifstream ifs(input_filename);
istream_iterator<int> in(ifs),eof;
// copy(in,eof,back_inserter(vec));
ofstream odd_ofs(odd_filename);
ofstream even_ofs(even_filename);
ostream_iterator<int> odd_out(odd_ofs,"\n");
ostream_iterator<int> even_out(even_ofs," ");
for_each(in,eof,
[](const int i){cout << i << "\n";});
for_each(in,eof,
[&odd_out, &even_out](const int i)
{*(i & 0x1 ? odd_out : even_out)++ = i;});
}
int main()
{
someMethod("number.txt","odd.txt","even.txt");
return 0;
}
| [
"feiwofeifeixiaowo@gmail.com"
] | feiwofeifeixiaowo@gmail.com |
80e290dae9385910a44edbdfbe0d49daa4a75693 | 6b559f93b401b84d31e18a040864f2b1ea049682 | /MemZone.h | 6042d589f44a33e6bd65df0c3cadec4dcf4ebc85 | [] | no_license | fU9ANg/card | f4c499d608e378b04610ce4eb844b092c551b560 | 4add80c7081149808145e262cefaac358e5af8ef | refs/heads/master | 2021-01-13T01:44:45.512409 | 2013-12-23T12:40:39 | 2013-12-23T12:40:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,548 | h |
#ifndef _CARDSRV_MEMZONE_H_
#define _CARDSRV_MEMZONE_H_
#include "Define.h"
#include "MutexLock.h"
#define MAX_POOL_BUF 200
using namespace std;
template <typename TYPE>
class MemZone
{
public:
MemZone (int n = MAX_POOL_BUF)
{
this->m_size = n;
for (int i = 0; i < this->m_size; i++)
{
TYPE* p = new TYPE;
this->m_free_queue.push (p);
}
}
~MemZone ()
{
MutexLockGuard guard (m_lock);
while (!m_free_queue.empty ())
{
TYPE* p = this->m_free_queue.front ();
this->m_free_queue.pop ();
delete p;
}
}
TYPE* malloc ()
{
MutexLockGuard guard (m_lock);
if (m_free_queue.empty ())
{
#ifdef _POOL_EXTEND
for (int i = 0; i < this->m_size; i++)
{
TYPE* p = new TYPE;
this->m_free_queue.push (p);
}
m_size *= 2;
#else
return (NULL);
#endif
}
TYPE* p = m_free_queue.front ();
m_free_queue.pop ();
return (p);
}
int free (TYPE* i)
{
MutexLockGuard guard (m_lock);
m_free_queue.push (i);
return (0);
}
int size ()
{
return (m_size);
}
int used ()
{
MutexLockGuard guard (m_lock);
return (m_size - m_free_queue.size ());
}
private:
std::queue <TYPE*> m_free_queue;
std::vector <TYPE*> m_used_queue;
MutexLock m_lock;
int m_size;
};
#endif
| [
"bb.newlife@gmail.com"
] | bb.newlife@gmail.com |
f381a093063c36cc1bbe0f32f66765534474c089 | ef83a69f758e22708da1ca2f0a2ab2f855bcf38f | /WebKit-IFC/Source/WebKit/blackberry/WebKitSupport/InputHandler.h | ec916f8246b643d1071bf93e324595b4110ec64b | [
"BSD-2-Clause"
] | permissive | bichhawat/ifc4bc | 14446efad82b8cec530e7f7cb4d23236484d08b6 | 31d3184d14a112030c1bc0941ff5168f2eece797 | refs/heads/master | 2021-01-13T07:53:07.848605 | 2017-06-21T10:32:43 | 2017-06-21T10:32:43 | 94,991,089 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,960 | h | /*
* Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef InputHandler_h
#define InputHandler_h
#include <BlackBerryPlatformInputEvents.h>
#include <imf/input_data.h>
#include <wtf/RefPtr.h>
namespace WTF {
class String;
}
namespace WebCore {
class AttributeTextStyle;
class Element;
class Frame;
class HTMLInputElement;
class HTMLSelectElement;
class IntRect;
class Node;
}
namespace BlackBerry {
namespace Platform {
class KeyboardEvent;
}
namespace WebKit {
class WebPagePrivate;
class InputHandler {
public:
InputHandler(WebPagePrivate*);
~InputHandler();
enum FocusElementType { TextEdit, TextPopup /* Date/Time & Color */, SelectPopup, Plugin };
enum CaretScrollType { CenterAlways, CenterIfNeeded, EdgeIfNeeded };
bool isInputModeEnabled() const;
void setInputModeEnabled(bool active = true);
void focusedNodeChanged();
void nodeTextChanged(const WebCore::Node*);
void selectionChanged();
void frameUnloaded(const WebCore::Frame*);
bool handleKeyboardInput(const BlackBerry::Platform::KeyboardEvent&, bool changeIsPartOfComposition = false);
bool deleteSelection();
void insertText(const WTF::String&);
void clearField();
void cut();
void copy();
void paste();
void cancelSelection();
void setInputValue(const WTF::String&);
void setDelayKeyboardVisibilityChange(bool value);
void processPendingKeyboardVisibilityChange();
void notifyClientOfKeyboardVisibilityChange(bool visible);
bool isInputMode() const { return isActiveTextEdit(); }
bool isMultilineInputMode() const { return isActiveTextEdit() && elementType(m_currentFocusElement.get()) == BlackBerry::Platform::InputTypeTextArea; }
void ensureFocusElementVisible(bool centerFieldInDisplay = true);
void handleInputLocaleChanged(bool isRTL);
// PopupMenu methods.
bool willOpenPopupForNode(WebCore::Node*);
bool didNodeOpenPopup(WebCore::Node*);
bool openLineInputPopup(WebCore::HTMLInputElement*);
bool openSelectPopup(WebCore::HTMLSelectElement*);
void setPopupListIndex(int);
void setPopupListIndexes(int size, const bool* selecteds);
bool processingChange() const { return m_processingChange; }
void setProcessingChange(bool processingChange) { m_processingChange = processingChange; }
WTF::String elementText();
WebCore::IntRect boundingBoxForInputField();
// IMF driven calls.
bool setBatchEditingActive(bool);
bool setSelection(int start, int end, bool changeIsPartOfComposition = false);
int caretPosition() const;
bool deleteTextRelativeToCursor(int leftOffset, int rightOffset);
spannable_string_t* selectedText(int32_t flags);
spannable_string_t* textBeforeCursor(int32_t length, int32_t flags);
spannable_string_t* textAfterCursor(int32_t length, int32_t flags);
extracted_text_t* extractedTextRequest(extracted_text_request_t*, int32_t flags);
int32_t setComposingRegion(int32_t start, int32_t end);
int32_t finishComposition();
int32_t setComposingText(spannable_string_t*, int32_t relativeCursorPosition);
int32_t commitText(spannable_string_t*, int32_t relativeCursorPosition);
void spellCheckingRequestProcessed(int32_t id, spannable_string_t*);
private:
enum PendingKeyboardStateChange { NoChange, Visible, NotVisible };
void setElementFocused(WebCore::Element*);
void setPluginFocused(WebCore::Element*);
void setElementUnfocused(bool refocusOccuring = false);
void ensureFocusTextElementVisible(CaretScrollType = CenterAlways);
void ensureFocusPluginElementVisible();
void clearCurrentFocusElement();
bool selectionAtStartOfElement();
bool selectionAtEndOfElement();
WebCore::IntRect rectForCaret(int index);
bool isActiveTextEdit() const { return m_currentFocusElement && m_currentFocusElementType == TextEdit; }
bool isActiveTextPopup() const { return m_currentFocusElement && m_currentFocusElementType == TextPopup; }
bool isActiveSelectPopup() const { return m_currentFocusElement && m_currentFocusElementType == SelectPopup; }
bool isActivePlugin() const { return m_currentFocusElement && m_currentFocusElementType == Plugin; }
bool openDatePopup(WebCore::HTMLInputElement*, BlackBerry::Platform::BlackBerryInputType);
bool openColorPopup(WebCore::HTMLInputElement*);
bool executeTextEditCommand(const WTF::String&);
BlackBerry::Platform::BlackBerryInputType elementType(WebCore::Element*) const;
int selectionStart() const;
int selectionEnd() const;
int selectionPosition(bool start) const;
bool selectionActive() const { return selectionStart() != selectionEnd(); }
bool compositionActive() const { return compositionLength(); }
unsigned compositionLength() const { return m_composingTextEnd - m_composingTextStart; }
spannable_string_t* spannableTextInRange(int start, int end, int32_t flags);
void addAttributedTextMarker(int start, int end, const WebCore::AttributeTextStyle&);
void removeAttributedTextMarker();
bool deleteText(int start, int end);
bool setTextAttributes(int insertionPoint, spannable_string_t*);
bool setText(spannable_string_t*);
bool setSpannableTextAndRelativeCursor(spannable_string_t*, int relativeCursorPosition, bool markTextAsComposing);
bool removeComposedText();
bool setRelativeCursorPosition(int insertionPoint, int relativeCursorPosition);
bool setCursorPosition(int location);
span_t* firstSpanInString(spannable_string_t*, SpannableStringAttribute);
bool isTrailingSingleCharacter(span_t*, unsigned, unsigned);
void learnText();
void sendLearnTextDetails(const WTF::String&);
WebPagePrivate* m_webPage;
RefPtr<WebCore::Element> m_currentFocusElement;
bool m_inputModeEnabled;
bool m_processingChange;
bool m_changingFocus;
FocusElementType m_currentFocusElementType;
int m_currentFocusElementTextEditMask;
int m_composingTextStart;
int m_composingTextEnd;
PendingKeyboardStateChange m_pendingKeyboardVisibilityChange;
bool m_delayKeyboardVisibilityChange;
};
}
}
#endif // InputHandler_h
| [
"abhishekbichhawat@gmail.com"
] | abhishekbichhawat@gmail.com |
1c4fbf4e728d2d9595409661aa31d5f3fc4cbb43 | ed7c9cc410aed29d40f19c6975844f347b5b6aa6 | /lib/Transforms/Vectorize/SVELoopVectorize.cpp | 66fec9eac6c6729eaf7e1cdc2444d6f4ab2be115 | [
"NCSA"
] | permissive | kito-cheng/LLVM-SVE | 6b84c39b743279d8675cc9cf487725248d6f054f | 6861c8827c93a2d15648b061e3a5bdbad80a3abf | refs/heads/master | 2020-04-22T10:41:04.143316 | 2018-10-30T16:10:16 | 2018-10-30T16:10:16 | 170,313,091 | 2 | 2 | NOASSERTION | 2019-02-12T12:19:18 | 2019-02-12T12:19:16 | null | UTF-8 | C++ | false | false | 344,168 | cpp | //===- SVELoopVectorize.cpp - A Loop Vectorizer ------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the LLVM loop vectorizer. This pass modifies 'vectorizable' loops
// and generates target-independent LLVM-IR.
// The vectorizer uses the TargetTransformInfo analysis to estimate the costs
// of instructions in order to estimate the profitability of vectorization.
//
// The loop vectorizer combines consecutive loop iterations into a single
// 'wide' iteration. After this transformation the index is incremented
// by the SIMD vector width, and not by one.
//
// This pass has three parts:
// 1. The main loop pass that drives the different parts.
// 2. LoopVectorizationLegality - A unit that checks for the legality
// of the vectorization.
// 3. InnerLoopVectorizer - A unit that performs the actual
// widening of instructions.
// 4. LoopVectorizationCostModel - A unit that checks for the profitability
// of vectorization. It decides on the optimal vector width, which
// can be one, if vectorization is not profitable.
//
//===----------------------------------------------------------------------===//
//
// The reduction-variable vectorization is based on the paper:
// D. Nuzman and R. Henderson. Multi-platform Auto-vectorization.
//
// Variable uniformity checks are inspired by:
// Karrenberg, R. and Hack, S. Whole Function Vectorization.
//
// The interleaved access vectorization is based on the paper:
// Dorit Nuzman, Ira Rosen and Ayal Zaks. Auto-Vectorization of Interleaved
// Data for SIMD
//
// Other ideas/concepts are from:
// A. Zaks and D. Nuzman. Autovectorization in GCC-two years later.
//
// S. Maleki, Y. Gao, M. Garzaran, T. Wong and D. Padua. An Evaluation of
// Vectorizing Compilers.
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/LoopVersioning.h"
#include "llvm/Transforms/LVCommon.h"
#include "llvm/Transforms/Vectorize.h"
#include <algorithm>
#include <functional>
#include <map>
#include <tuple>
using namespace llvm;
using namespace llvm::PatternMatch;
#define LV_NAME "sve-loop-vectorize"
#define DEBUG_TYPE LV_NAME
#ifndef NDEBUG
#define NODEBUG_EARLY_BAILOUT() \
do { if (!::llvm::DebugFlag || !::llvm::isCurrentDebugType(DEBUG_TYPE)) \
{ return false; } } while (0)
#else
#define NODEBUG_EARLY_BAILOUT() { return false; }
#endif
STATISTIC(LoopsVectorized, "Number of loops vectorized");
STATISTIC(LoopsVectorizedWA, "Number of loops vectorized with WA");
STATISTIC(LoopsAnalyzed, "Number of loops analyzed for vectorization");
/// We don't interleave loops with a known constant trip count below this
/// number.
static const unsigned TinyTripCountInterleaveThreshold = 128;
/// Maximum vectorization interleave count.
const unsigned MaxInterleaveFactor = 16;
static cl::opt<bool> EnableScalableVectorisation(
"force-scalable-vectorization", cl::init(false), cl::Hidden,
cl::ZeroOrMore,
cl::desc("Enable vectorization using scalable vectors"));
static cl::opt<bool> EnableVectorPredication(
"force-vector-predication", cl::init(false), cl::Hidden, cl::ZeroOrMore,
cl::desc("Enable predicated vector operations."));
static cl::opt<bool> EnableNonConsecutiveStrideIndVars(
"enable-non-consecutive-stride-ind-vars", cl::init(false), cl::Hidden,
cl::desc("Enable recognition of induction variables that aren't "
"consecutive between loop iterations"));
static cl::opt<unsigned> VectorizerMemSetThreshold(
"vectorize-memset-threshold", cl::init(8),
cl::Hidden, cl::desc("Maximum (write size in bytes / aligment)"
" ratio for the memset."));
static cl::opt<bool> VectorizeMemset(
"vectorize-memset", cl::init(true), cl::Hidden,
cl::desc("Enable vectorization of loops with memset calls in the loop "
"body"));
/// Create an analysis remark that explains why vectorization failed
///
/// \p PassName is the name of the pass (e.g. can be AlwaysPrint). \p
/// RemarkName is the identifier for the remark. If \p I is passed it is an
/// instruction that prevents vectorization. Otherwise \p TheLoop is used for
/// the location of the remark. \return the remark object that can be
/// streamed to.
static OptimizationRemarkAnalysis
createMissedAnalysis(const char *PassName, StringRef RemarkName, Loop *TheLoop,
Instruction *I = nullptr) {
Value *CodeRegion = TheLoop->getHeader();
DebugLoc StartLoc = TheLoop->getLocRange().getStart();
DebugLoc EndLoc = TheLoop->getLocRange().getEnd();
if (I) {
CodeRegion = I->getParent();
// If there is no debug location attached to the instruction, revert back to
// using the loop's.
if (I->getDebugLoc())
StartLoc = EndLoc = I->getDebugLoc();
}
auto LocRange = DiagnosticLocation(StartLoc, EndLoc);
OptimizationRemarkAnalysis R(PassName, RemarkName, LocRange, CodeRegion);
R << "loop not vectorized: ";
return R;
}
namespace {
// Forward declarations.
class LoopVectorizeHints;
class LoopVectorizationLegality;
class LoopVectorizationCostModel;
class LoopVectorizationRequirements;
/// Information about vectorization costs
struct VectorizationFactor {
unsigned Width; // Vector width with best cost
unsigned Cost; // Cost of the loop with that width
bool isFixed; // Is the width an absolute value or a scale.
};
/// Returns true if the given loop body has a cycle, excluding the loop
/// itself.
static bool hasCyclesInLoopBody(const Loop &L) {
if (!L.empty())
return true;
for (const auto &SCC :
make_range(scc_iterator<Loop, LoopBodyTraits>::begin(L),
scc_iterator<Loop, LoopBodyTraits>::end(L))) {
if (SCC.size() > 1) {
DEBUG(dbgs() << "LVL: Detected a cycle in the loop body:\n");
DEBUG(L.dump());
return true;
}
}
return false;
}
/// A helper function for converting Scalar types to vector types.
/// If the incoming type is void, we return void. If the VF is 1, we return
/// the scalar type.
static Type *ToVectorTy(Type *Scalar, unsigned VF, bool IsScalable) {
if (Scalar->isVoidTy() || VF == 1)
return Scalar;
return VectorType::get(Scalar, VF, IsScalable);
}
static Type* ToVectorTy(Type *Scalar, VectorizationFactor VF) {
if (Scalar->isVoidTy() || VF.Width == 1)
return Scalar;
return VectorType::get(Scalar, VF.Width, !VF.isFixed);
}
/// A helper function that returns GEP instruction and knows to skip a
/// 'bitcast'. The 'bitcast' may be skipped if the source and the destination
/// pointee types of the 'bitcast' have the same size.
/// For example:
/// bitcast double** %var to i64* - can be skipped
/// bitcast double** %var to i8* - can not
static GetElementPtrInst *getGEPInstruction(Value *Ptr) {
if (isa<GetElementPtrInst>(Ptr))
return cast<GetElementPtrInst>(Ptr);
if (isa<BitCastInst>(Ptr) &&
isa<GetElementPtrInst>(cast<BitCastInst>(Ptr)->getOperand(0))) {
Type *BitcastTy = Ptr->getType();
Type *GEPTy = cast<BitCastInst>(Ptr)->getSrcTy();
if (!isa<PointerType>(BitcastTy) || !isa<PointerType>(GEPTy))
return nullptr;
Type *Pointee1Ty = cast<PointerType>(BitcastTy)->getPointerElementType();
Type *Pointee2Ty = cast<PointerType>(GEPTy)->getPointerElementType();
const DataLayout &DL = cast<BitCastInst>(Ptr)->getModule()->getDataLayout();
if (DL.getTypeSizeInBits(Pointee1Ty) == DL.getTypeSizeInBits(Pointee2Ty))
return cast<GetElementPtrInst>(cast<BitCastInst>(Ptr)->getOperand(0));
}
return nullptr;
}
// FIXME: The following helper functions have multiple implementations
// in the project. They can be effectively organized in a common Load/Store
// utilities unit.
/// A helper function that returns the pointer operand of a load or store
/// instruction.
static Value *getPointerOperand(Value *I) {
if (auto *LI = dyn_cast<LoadInst>(I))
return LI->getPointerOperand();
if (auto *SI = dyn_cast<StoreInst>(I))
return SI->getPointerOperand();
return nullptr;
}
/// A helper function that returns the alignment of load or store instruction.
static unsigned getMemInstAlignment(Value *I) {
assert((isa<LoadInst>(I) || isa<StoreInst>(I)) &&
"Expected Load or Store instruction");
if (auto *LI = dyn_cast<LoadInst>(I))
return LI->getAlignment();
return cast<StoreInst>(I)->getAlignment();
}
/// A helper function that returns the address space of the pointer operand of
/// load or store instruction.
static unsigned getMemInstAddressSpace(Value *I) {
assert((isa<LoadInst>(I) || isa<StoreInst>(I)) &&
"Expected Load or Store instruction");
if (auto *LI = dyn_cast<LoadInst>(I))
return LI->getPointerAddressSpace();
return cast<StoreInst>(I)->getPointerAddressSpace();
}
/// A helper function that adds a 'fast' flag to floating-point operations.
static Value *addFastMathFlag(Value *V) {
if (isa<FPMathOperator>(V)) {
FastMathFlags Flags;
Flags.setUnsafeAlgebra();
cast<Instruction>(V)->setFastMathFlags(Flags);
}
return V;
}
/// A helper function that returns an integer or floating-point constant with
/// value C.
static Constant *getSignedIntOrFpConstant(Type *Ty, int64_t C) {
return Ty->isIntegerTy() ? ConstantInt::getSigned(Ty, C)
: ConstantFP::get(Ty, C);
}
/// InnerLoopVectorizer vectorizes loops which contain only one basic
/// block to a specified vectorization factor (VF).
/// This class performs the widening of scalars into vectors, or multiple
/// scalars. This class also implements the following features:
/// * It inserts an epilogue loop for handling loops that don't have iteration
/// counts that are known to be a multiple of the vectorization factor.
/// * It handles the code generation for reduction variables.
/// * Scalarization (implementation using scalars) of un-vectorizable
/// instructions.
/// InnerLoopVectorizer does not perform any vectorization-legality
/// checks, and relies on the caller to check for the different legality
/// aspects. The InnerLoopVectorizer relies on the
/// LoopVectorizationLegality class to provide information about the induction
/// and reduction variables that were found to a given vectorization factor.
class InnerLoopVectorizer {
public:
InnerLoopVectorizer(Loop *OrigLoop, PredicatedScalarEvolution &PSE,
LoopInfo *LI, DominatorTree *DT,
const TargetLibraryInfo *TLI,
const TargetTransformInfo *TTI, AssumptionCache *AC,
OptimizationRemarkEmitter *ORE,
unsigned VecWidth, unsigned UnrollFactor,
bool VecWidthIsFixed)
: OrigLoop(OrigLoop), PSE(PSE), LI(LI), DT(DT), TLI(TLI), TTI(TTI),
AC(AC), ORE(ORE), VF(VecWidth), Scalable(!VecWidthIsFixed),
UsePredication(EnableVectorPredication && isScalable()),
UF(UnrollFactor), Builder(PSE.getSE()->getContext()),
Induction(nullptr), OldInduction(nullptr), InductionStep(nullptr),
WidenMap(UnrollFactor), VecBodyPostDom(nullptr), TripCount(nullptr),
VectorTripCount(nullptr), Legal(nullptr), AddedSafetyChecks(false),
LatchBranch(nullptr), IdxEnd(nullptr), IdxEndV(nullptr) {}
// Perform the actual loop widening (vectorization).
// MinimumBitWidths maps scalar integer values to the smallest bitwidth they
// can be validly truncated to. The cost model has assumed this truncation
// will happen when vectorizing.
void vectorize(LoopVectorizationLegality *L,
MapVector<Instruction *, uint64_t> MinimumBitWidths) {
MinBWs = MinimumBitWidths;
Legal = L;
// Create a new empty loop. Unlink the old loop and connect the new one.
if (UsePredication)
createEmptyLoopWithPredication();
else
createEmptyLoop();
// Widen each instruction in the old loop to a new one in the new loop.
// Use the Legality module to find the induction and reduction variables.
vectorizeLoop();
}
// Return true if any runtime check is added.
bool areSafetyChecksAdded() { return AddedSafetyChecks; }
virtual ~InnerLoopVectorizer() {}
bool isScalable() const {
return (VF > 1) && Scalable;
}
protected:
/// A small list of PHINodes.
typedef SmallVector<PHINode *, 4> PhiVector;
/// When we unroll loops we have multiple vector values for each scalar.
/// This data structure holds the unrolled and vectorized values that
/// originated from one scalar instruction.
typedef SmallVector<Value *, 2> VectorParts;
// When we if-convert we need to create edge masks. We have to cache values
// so that we don't end up with exponential recursion/IR.
typedef DenseMap<std::pair<BasicBlock *, BasicBlock *>, VectorParts>
EdgeMaskCache;
/// \brief Add checks for strides that were assumed to be 1.
///
/// Returns the last check instruction and the first check instruction in the
/// pair as (first, last).
std::pair<Instruction *, Instruction *> addStrideCheck(Instruction *Loc);
/// Create an empty loop, based on the loop ranges of the old loop.
void createEmptyLoop();
/// Create an empty loop, using per-element predication to control termination
void createEmptyLoopWithPredication();
/// Set up the values of the IVs correctly when exiting the vector loop.
void fixupIVUsers(PHINode *OrigPhi, const InductionDescriptor &II,
Value *CountRoundDown, Value *EndValue,
BasicBlock *MiddleBlock);
/// Create a new induction variable inside L.
PHINode *createInductionVariable(Loop *L, Value *Start, Value *End,
Value *Step, Instruction *DL);
/// Copy and widen the instructions from the old loop.
virtual void vectorizeLoop();
/// Fix a first-order recurrence. This is the second phase of vectorizing
/// this phi node.
void fixFirstOrderRecurrence(PHINode *Phi);
/// \brief The Loop exit block may have single value PHI nodes where the
/// incoming value is 'Undef'. While vectorizing we only handled real values
/// that were defined inside the loop. Here we fix the 'undef case'.
/// See PR14725.
void fixLCSSAPHIs();
/// Shrinks vector element sizes based on information in "MinBWs".
void truncateToMinimalBitwidths();
/// A helper function that computes the predicate of the block BB, assuming
/// that the header block of the loop is set to True. It returns the *entry*
/// mask for the block BB.
VectorParts createBlockInMask(BasicBlock *BB);
/// A helper function that computes the predicate of the edge between SRC
/// and DST.
VectorParts createEdgeMask(BasicBlock *Src, BasicBlock *Dst);
/// A helper function to vectorize a single BB within the innermost loop.
void vectorizeBlockInLoop(BasicBlock *BB, PhiVector *PV);
/// Vectorize a single PHINode in a block. This method handles the induction
/// variable canonicalization. It supports both VF = 1 for unrolled loops and
/// arbitrary length vectors.
void widenPHIInstruction(Instruction *PN, VectorParts &Entry, unsigned UF,
unsigned VF, PhiVector *PV);
// Patch up the condition for a branch instruction after the block has been
// vectorized; only used with predication for now.
void patchLatchBranch(BranchInst *Br);
/// Insert the new loop to the loop hierarchy and pass manager
/// and update the analysis passes.
void updateAnalysis();
/// This instruction is un-vectorizable. Implement it as a sequence
/// of scalars. If \p IfPredicateStore is true we need to 'hide' each
/// scalarized instruction behind an if block predicated on the control
/// dependence of the instruction.
virtual void scalarizeInstruction(Instruction *Instr,
bool IfPredicateStore = false);
/// Vectorize Load and Store instructions,
virtual void vectorizeMemoryInstruction(Instruction *Instr);
virtual void vectorizeArithmeticGEP(Instruction *Instr);
virtual void vectorizeGEPInstruction(Instruction *Instr);
virtual void vectorizeMemsetInstruction(MemSetInst *MSI);
/// Create a broadcast instruction. This method generates a broadcast
/// instruction (shuffle) for loop invariant values and for the induction
/// value. If this is the induction variable then we extend it to N, N+1, ...
/// this is needed because each iteration in the loop corresponds to a SIMD
/// element.
virtual Value *getBroadcastInstrs(Value *V);
/// This function adds (StartIdx, StartIdx + Step, StartIdx + 2*Step, ...)
/// to each vector element of Val. The sequence starts at StartIndex.
/// \p Opcode is relevant for FP induction variable.
virtual Value *getStepVector(Value *Val, int StartIdx, Value *Step,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd);
virtual Value *getStepVector(Value *Val, Value* Start, Value *Step,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd);
virtual Value *getElementCount(Type* ETy, unsigned NumElts, bool Scalable,
Type* RTy = nullptr);
/// This function adds (StartIdx, StartIdx + Step, StartIdx + 2*Step, ...)
/// to each vector element of Val. The sequence starts at StartIndex.
/// Step is a SCEV. In order to get StepValue it takes the existing value
/// from SCEV or creates a new using SCEVExpander.
virtual Value *getStepVector(Value *Val, Value *Start, const SCEV *Step,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd);
/// Create a vector induction variable based on an existing scalar one.
/// Currently only works for integer primary induction variables with
/// a constant step.
/// If TruncType is provided, instead of widening the original IV, we
/// widen a version of the IV truncated to TruncType.
void widenInductionVariable(const InductionDescriptor &II, VectorParts &Entry,
IntegerType *TruncType = nullptr);
/// When we go over instructions in the basic block we rely on previous
/// values within the current basic block or on loop invariant values.
/// When we widen (vectorize) values we place them in the map. If the values
/// are not within the map, they have to be loop invariant, so we simply
/// broadcast them into a vector.
VectorParts &getVectorValue(Value *V);
/// Try to vectorize the interleaved access group that \p Instr belongs to.
void vectorizeInterleaveGroup(Instruction *Instr);
/// Generate a shuffle sequence that will reverse the vector Vec.
virtual Value *reverseVector(Value *Vec);
/// Returns (and creates if needed) the original loop trip count.
Value *getOrCreateTripCount(Loop *NewLoop);
/// Returns (and creates if needed) the trip count of the widened loop.
Value *getOrCreateVectorTripCount(Loop *NewLoop);
/// Returns (and creates if needed) the induction increment per iteration of
/// the widened loop.
Value *getOrCreateInductionStep(Loop *NewLoop);
/// Emit a bypass check to see if the trip count would overflow, or we
/// wouldn't have enough iterations to execute one vector loop.
void emitMinimumIterationCountCheck(Loop *L, Value *Min, BasicBlock *Bypass);
/// Emit a bypass check to see if the vector trip count is nonzero.
void emitVectorLoopEnteredCheck(Loop *L, BasicBlock *Bypass);
/// Emit a bypass check to see if all of the SCEV assumptions we've
/// had to make are correct.
void emitSCEVChecks(Loop *L, BasicBlock *Bypass);
/// Emit bypass checks to check any memory assumptions we may have made.
void emitMemRuntimeChecks(Loop *L, BasicBlock *Bypass);
/// Add additional metadata to \p To that was not present on \p Orig.
///
/// Currently this is used to add the noalias annotations based on the
/// inserted memchecks. Use this for instructions that are *cloned* into the
/// vector loop.
void addNewMetadata(Instruction *To, const Instruction *Orig);
/// Add metadata from one instruction to another.
///
/// This includes both the original MDs from \p From and additional ones (\see
/// addNewMetadata). Use this for *newly created* instructions in the vector
/// loop.
void addMetadata(Instruction *To, const Instruction *From);
/// \brief Similar to the previous function but it adds the metadata to a
/// vector of instructions.
void addMetadata(SmallVectorImpl<Value *> &To, const Instruction *From);
/// This is a helper class that holds the vectorizer state. It maps scalar
/// instructions to vector instructions. When the code is 'unrolled' then
/// then a single scalar value is mapped to multiple vector parts. The parts
/// are stored in the VectorPart type.
struct ValueMap {
/// C'tor. UnrollFactor controls the number of vectors ('parts') that
/// are mapped.
ValueMap(unsigned UnrollFactor) : UF(UnrollFactor) {}
/// \return True if 'Key' is saved in the Value Map.
bool has(Value *Key) const { return MapStorage.count(Key); }
/// Initializes a new entry in the map. Sets all of the vector parts to the
/// save value in 'Val'.
/// \return A reference to a vector with splat values.
VectorParts &splat(Value *Key, Value *Val) {
VectorParts &Entry = MapStorage[Key];
Entry.assign(UF, Val);
return Entry;
}
///\return A reference to the value that is stored at 'Key'.
VectorParts &get(Value *Key) {
VectorParts &Entry = MapStorage[Key];
if (Entry.empty())
Entry.resize(UF);
assert(Entry.size() == UF);
return Entry;
}
private:
/// The unroll factor. Each entry in the map stores this number of vector
/// elements.
unsigned UF;
/// Map storage. We use std::map and not DenseMap because insertions to a
/// dense map invalidates its iterators.
std::map<Value *, VectorParts> MapStorage;
};
///\brief Perform CSE of induction variable instructions.
void CSE(SmallVector<BasicBlock *, 4> &BBs, SmallSet<BasicBlock *, 2> &Preds);
/// The original loop.
Loop *OrigLoop;
/// A wrapper around ScalarEvolution used to add runtime SCEV checks. Applies
/// dynamic knowledge to simplify SCEV expressions and converts them to a
/// more usable form.
PredicatedScalarEvolution &PSE;
/// Loop Info.
LoopInfo *LI;
/// Dominator Tree.
DominatorTree *DT;
/// Target Library Info.
const TargetLibraryInfo *TLI;
/// Target Transform Info.
const TargetTransformInfo *TTI;
/// Assumption Cache.
AssumptionCache *AC;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter *ORE;
/// Alias Analysis.
AliasAnalysis *AA;
/// \brief LoopVersioning. It's only set up (non-null) if memchecks were
/// used.
///
/// This is currently only used to add no-alias metadata based on the
/// memchecks. The actually versioning is performed manually.
std::unique_ptr<LoopVersioning> LVer;
/// The vectorization SIMD factor to use. Each vector will have this many
/// vector elements.
unsigned VF;
bool Scalable;
bool UsePredication;
protected:
/// Test if instruction I is the exit instruction of some recurrence. If yes,
/// it sets RD with the associated RecurrenceDescriptor instance.
bool testHorizontalReductionExitInst(Instruction *I, RecurrenceDescriptor &RD);
/// The vectorization unroll factor to use. Each scalar is vectorized to this
/// many different vector instructions.
unsigned UF;
/// The builder that we use
IRBuilder<> Builder;
// --- Vectorization state ---
/// The vector-loop preheader.
BasicBlock *LoopVectorPreHeader;
/// The scalar-loop preheader.
BasicBlock *LoopScalarPreHeader;
/// Middle Block between the vector and the scalar.
BasicBlock *LoopMiddleBlock;
/// The ExitBlock of the scalar loop.
BasicBlock *LoopExitBlock;
/// The vector loop body.
SmallVector<BasicBlock *, 4> LoopVectorBody;
/// The scalar loop body.
BasicBlock *LoopScalarBody;
/// A list of all bypass blocks. The first block is the entry of the loop.
SmallVector<BasicBlock *, 4> LoopBypassBlocks;
/// The new Induction variable which was added to the new block.
PHINode *Induction;
/// The induction variable of the old basic block.
PHINode *OldInduction;
/// Value of the induction var for the next loop trip
Value *InductionStep;
/// Holds the entry predicates for the current iteration of the vector body.
PhiVector Predicate;
/// Holds the extended (to the widest induction type) start index.
Value *ExtendedIdx;
/// Maps scalars to widened vectors.
ValueMap WidenMap;
/// Store instructions that should be predicated, as a pair
/// <StoreInst, Predicate>
SmallVector<std::pair<StoreInst *, Value *>, 4> PredicatedStores;
EdgeMaskCache MaskCache;
// Loop vector body current post-dominator block.
BasicBlock *VecBodyPostDom;
typedef std::pair<BasicBlock *, BasicBlock *> DomEdge;
SmallVector<DomEdge, 4> VecBodyDomEdges;
// Conditional blocks due to if-conversion.
SmallSet<BasicBlock *, 2> PredicatedBlocks;
/// Trip count of the original loop.
Value *TripCount;
/// Trip count of the widened loop (TripCount - TripCount % (VF*UF))
Value *VectorTripCount;
/// Map of scalar integer values to the smallest bitwidth they can be legally
/// represented as. The vector equivalents of these values should be truncated
/// to this type.
MapVector<Instruction *, uint64_t> MinBWs;
LoopVectorizationLegality *Legal;
// Record whether runtime checks are added.
bool AddedSafetyChecks;
/// Stores new branch for vectorized latch block so it
/// can be patched up after vectorization
BranchInst *LatchBranch;
/// TODO -- rename this and InductionStep?
/// TODO -- move both to exit info descriptor?
Value *IdxEnd;
Value *IdxEndV;
// Holds the end values for each induction variable. We save the end values
// so we can later fix-up the external users of the induction variables.
DenseMap<PHINode *, Value *> IVEndValues;
};
class InnerLoopUnroller : public InnerLoopVectorizer {
public:
InnerLoopUnroller(Loop *OrigLoop, PredicatedScalarEvolution &PSE,
LoopInfo *LI, DominatorTree *DT,
const TargetLibraryInfo *TLI,
const TargetTransformInfo *TTI, AssumptionCache *AC,
OptimizationRemarkEmitter *ORE,
unsigned UnrollFactor)
: InnerLoopVectorizer(OrigLoop, PSE, LI, DT, TLI, TTI, AC, ORE, 1,
UnrollFactor, true) {}
private:
void scalarizeInstruction(Instruction *Instr,
bool IfPredicateStore = false) override;
void vectorizeMemoryInstruction(Instruction *Instr) override;
Value *getBroadcastInstrs(Value *V) override;
Value *getStepVector(Value *Val, int StartIdx, Value *Step,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd) override;
Value *getStepVector(Value *Val, Value *Start, Value *Step,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd) override;
Value *getStepVector(Value *Val, Value *Start, const SCEV *StepSCEV,
Instruction::BinaryOps Opcode =
Instruction::BinaryOpsEnd) override;
Value *reverseVector(Value *Vec) override;
};
/// \brief Look for a meaningful debug location on the instruction or it's
/// operands.
static Instruction *getDebugLocFromInstOrOperands(Instruction *I) {
if (!I)
return I;
DebugLoc Empty;
if (I->getDebugLoc() != Empty)
return I;
for (User::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) {
if (Instruction *OpInst = dyn_cast<Instruction>(*OI))
if (OpInst->getDebugLoc() != Empty)
return OpInst;
}
return I;
}
/// \brief Set the debug location in the builder using the debug location in the
/// instruction.
static void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) {
if (const Instruction *Inst = dyn_cast_or_null<Instruction>(Ptr))
B.SetCurrentDebugLocation(Inst->getDebugLoc());
else
B.SetCurrentDebugLocation(DebugLoc());
}
#ifndef NDEBUG
/// \return string containing a file name and a line # for the given loop.
static std::string getDebugLocString(const Loop *L) {
std::string Result;
if (L) {
raw_string_ostream OS(Result);
if (const DebugLoc LoopDbgLoc = L->getStartLoc())
LoopDbgLoc.print(OS);
else
// Just print the module name.
OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
OS.flush();
}
return Result;
}
#endif
/// \brief Propagate known metadata from one instruction to another.
static void propagateMetadata(Instruction *To, const Instruction *From) {
SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata;
From->getAllMetadataOtherThanDebugLoc(Metadata);
for (auto M : Metadata) {
unsigned Kind = M.first;
// These are safe to transfer (this is safe for TBAA, even when we
// if-convert, because should that metadata have had a control dependency
// on the condition, and thus actually aliased with some other
// non-speculated memory access when the condition was false, this would be
// caught by the runtime overlap checks).
if (Kind != LLVMContext::MD_tbaa && Kind != LLVMContext::MD_alias_scope &&
Kind != LLVMContext::MD_noalias && Kind != LLVMContext::MD_fpmath &&
Kind != LLVMContext::MD_nontemporal)
continue;
To->setMetadata(Kind, M.second);
}
}
void InnerLoopVectorizer::addNewMetadata(Instruction *To,
const Instruction *Orig) {
// If the loop was versioned with memchecks, add the corresponding no-alias
// metadata.
if (LVer && (isa<LoadInst>(Orig) || isa<StoreInst>(Orig)))
LVer->annotateInstWithNoAlias(To, Orig);
}
void InnerLoopVectorizer::addMetadata(Instruction *To,
const Instruction *From) {
propagateMetadata(To, From);
addNewMetadata(To, From);
}
void InnerLoopVectorizer::addMetadata(SmallVectorImpl<Value *> &To,
const Instruction *From) {
for (Value *V : To)
if (Instruction *I = dyn_cast<Instruction>(V))
addMetadata(I, From);
}
/// \brief The group of interleaved loads/stores sharing the same stride and
/// close to each other.
///
/// Each member in this group has an index starting from 0, and the largest
/// index should be less than interleaved factor, which is equal to the absolute
/// value of the access's stride.
///
/// E.g. An interleaved load group of factor 4:
/// for (unsigned i = 0; i < 1024; i+=4) {
/// a = A[i]; // Member of index 0
/// b = A[i+1]; // Member of index 1
/// d = A[i+3]; // Member of index 3
/// ...
/// }
///
/// An interleaved store group of factor 4:
/// for (unsigned i = 0; i < 1024; i+=4) {
/// ...
/// A[i] = a; // Member of index 0
/// A[i+1] = b; // Member of index 1
/// A[i+2] = c; // Member of index 2
/// A[i+3] = d; // Member of index 3
/// }
///
/// Note: the interleaved load group could have gaps (missing members), but
/// the interleaved store group doesn't allow gaps.
class InterleaveGroup {
public:
InterleaveGroup(Instruction *Instr, int Stride, unsigned Align)
: Align(Align), SmallestKey(0), LargestKey(0), InsertPos(Instr) {
assert(Align && "The alignment should be non-zero");
Factor = std::abs(Stride);
assert(Factor > 1 && "Invalid interleave factor");
Reverse = Stride < 0;
Members[0] = Instr;
}
bool isReverse() const { return Reverse; }
unsigned getFactor() const { return Factor; }
unsigned getAlignment() const { return Align; }
unsigned getNumMembers() const { return Members.size(); }
/// \brief Try to insert a new member \p Instr with index \p Index and
/// alignment \p NewAlign. The index is related to the leader and it could be
/// negative if it is the new leader.
///
/// \returns false if the instruction doesn't belong to the group.
bool insertMember(Instruction *Instr, int Index, unsigned NewAlign) {
assert(NewAlign && "The new member's alignment should be non-zero");
int Key = Index + SmallestKey;
// Skip if there is already a member with the same index.
if (Members.count(Key))
return false;
if (Key > LargestKey) {
// The largest index is always less than the interleave factor.
if (Index >= static_cast<int>(Factor))
return false;
LargestKey = Key;
} else if (Key < SmallestKey) {
// The largest index is always less than the interleave factor.
if (LargestKey - Key >= static_cast<int>(Factor))
return false;
SmallestKey = Key;
}
// It's always safe to select the minimum alignment.
Align = std::min(Align, NewAlign);
Members[Key] = Instr;
return true;
}
/// \brief Get the member with the given index \p Index
///
/// \returns nullptr if contains no such member.
Instruction *getMember(unsigned Index) const {
int Key = SmallestKey + Index;
if (!Members.count(Key))
return nullptr;
return Members.find(Key)->second;
}
/// \brief Get the index for the given member. Unlike the key in the member
/// map, the index starts from 0.
unsigned getIndex(Instruction *Instr) const {
for (auto I : Members)
if (I.second == Instr)
return I.first - SmallestKey;
llvm_unreachable("InterleaveGroup contains no such member");
}
Instruction *getInsertPos() const { return InsertPos; }
void setInsertPos(Instruction *Inst) { InsertPos = Inst; }
private:
unsigned Factor; // Interleave Factor.
bool Reverse;
unsigned Align;
DenseMap<int, Instruction *> Members;
int SmallestKey;
int LargestKey;
// To avoid breaking dependences, vectorized instructions of an interleave
// group should be inserted at either the first load or the last store in
// program order.
//
// E.g. %even = load i32 // Insert Position
// %add = add i32 %even // Use of %even
// %odd = load i32
//
// store i32 %even
// %odd = add i32 // Def of %odd
// store i32 %odd // Insert Position
Instruction *InsertPos;
};
/// \brief Drive the analysis of interleaved memory accesses in the loop.
///
/// Use this class to analyze interleaved accesses only when we can vectorize
/// a loop. Otherwise it's meaningless to do analysis as the vectorization
/// on interleaved accesses is unsafe.
///
/// The analysis collects interleave groups and records the relationships
/// between the member and the group in a map.
class InterleavedAccessInfo {
public:
InterleavedAccessInfo(PredicatedScalarEvolution &PSE, Loop *L,
DominatorTree *DT, LoopInfo *LI)
: PSE(PSE), TheLoop(L), DT(DT), LI(LI), LAI(nullptr),
RequiresScalarEpilogue(false) {}
~InterleavedAccessInfo() {
SmallSet<InterleaveGroup *, 4> DelSet;
// Avoid releasing a pointer twice.
for (auto &I : InterleaveGroupMap)
DelSet.insert(I.second);
for (auto *Ptr : DelSet)
delete Ptr;
}
/// \brief Analyze the interleaved accesses and collect them in interleave
/// groups. Substitute symbolic strides using \p Strides.
void analyzeInterleaving(const ValueToValueMap &Strides);
/// \brief Check if \p Instr belongs to any interleave group.
bool isInterleaved(Instruction *Instr) const {
return InterleaveGroupMap.count(Instr);
}
/// \brief Return the maximum interleave factor of all interleaved groups.
unsigned getMaxInterleaveFactor() const {
unsigned MaxFactor = 1;
for (auto &Entry : InterleaveGroupMap)
MaxFactor = std::max(MaxFactor, Entry.second->getFactor());
return MaxFactor;
}
/// \brief Get the interleave group that \p Instr belongs to.
///
/// \returns nullptr if doesn't have such group.
InterleaveGroup *getInterleaveGroup(Instruction *Instr) const {
if (InterleaveGroupMap.count(Instr))
return InterleaveGroupMap.find(Instr)->second;
return nullptr;
}
/// \brief Returns true if an interleaved group that may access memory
/// out-of-bounds requires a scalar epilogue iteration for correctness.
bool requiresScalarEpilogue() const { return RequiresScalarEpilogue; }
/// \brief Initialize the LoopAccessInfo used for dependence checking.
void setLAI(const LoopAccessInfo *Info) { LAI = Info; }
private:
/// A wrapper around ScalarEvolution, used to add runtime SCEV checks.
/// Simplifies SCEV expressions in the context of existing SCEV assumptions.
/// The interleaved access analysis can also add new predicates (for example
/// by versioning strides of pointers).
PredicatedScalarEvolution &PSE;
Loop *TheLoop;
DominatorTree *DT;
LoopInfo *LI;
const LoopAccessInfo *LAI;
/// True if the loop may contain non-reversed interleaved groups with
/// out-of-bounds accesses. We ensure we don't speculatively access memory
/// out-of-bounds by executing at least one scalar epilogue iteration.
bool RequiresScalarEpilogue;
/// Holds the relationships between the members and the interleave group.
DenseMap<Instruction *, InterleaveGroup *> InterleaveGroupMap;
/// Holds dependences among the memory accesses in the loop. It maps a source
/// access to a set of dependent sink accesses.
DenseMap<Instruction *, SmallPtrSet<Instruction *, 2>> Dependences;
/// \brief The descriptor for a strided memory access.
struct StrideDescriptor {
StrideDescriptor(int64_t Stride, const SCEV *Scev, uint64_t Size,
unsigned Align)
: Stride(Stride), Scev(Scev), Size(Size), Align(Align) {}
StrideDescriptor() = default;
// The access's stride. It is negative for a reverse access.
int64_t Stride = 0;
const SCEV *Scev = nullptr; // The scalar expression of this access
uint64_t Size = 0; // The size of the memory object.
unsigned Align = 0; // The alignment of this access.
};
/// \brief A type for holding instructions and their stride descriptors.
typedef std::pair<Instruction *, StrideDescriptor> StrideEntry;
/// \brief Create a new interleave group with the given instruction \p Instr,
/// stride \p Stride and alignment \p Align.
///
/// \returns the newly created interleave group.
InterleaveGroup *createInterleaveGroup(Instruction *Instr, int Stride,
unsigned Align) {
assert(!InterleaveGroupMap.count(Instr) &&
"Already in an interleaved access group");
InterleaveGroupMap[Instr] = new InterleaveGroup(Instr, Stride, Align);
return InterleaveGroupMap[Instr];
}
/// \brief Release the group and remove all the relationships.
void releaseGroup(InterleaveGroup *Group) {
for (unsigned i = 0; i < Group->getFactor(); i++)
if (Instruction *Member = Group->getMember(i))
InterleaveGroupMap.erase(Member);
delete Group;
}
/// \brief Collect all the accesses with a constant stride in program order.
void collectConstStrideAccesses(
MapVector<Instruction *, StrideDescriptor> &AccessStrideInfo,
const ValueToValueMap &Strides);
/// \brief Returns true if \p Stride is allowed in an interleaved group.
static bool isStrided(int Stride) {
unsigned Factor = std::abs(Stride);
return Factor >= 2 && Factor <= MaxInterleaveGroupFactor;
}
/// \brief Returns true if \p BB is a predicated block.
bool isPredicated(BasicBlock *BB) const {
return LoopAccessInfo::blockNeedsPredication(BB, TheLoop, DT);
}
/// \brief Returns true if LoopAccessInfo can be used for dependence queries.
bool areDependencesValid() const {
return LAI && LAI->getDepChecker().getDependences();
}
/// \brief Returns true if memory accesses \p A and \p B can be reordered, if
/// necessary, when constructing interleaved groups.
///
/// \p A must precede \p B in program order. We return false if reordering is
/// not necessary or is prevented because \p A and \p B may be dependent.
bool canReorderMemAccessesForInterleavedGroups(StrideEntry *A,
StrideEntry *B) const {
// Code motion for interleaved accesses can potentially hoist strided loads
// and sink strided stores. The code below checks the legality of the
// following two conditions:
//
// 1. Potentially moving a strided load (B) before any store (A) that
// precedes B, or
//
// 2. Potentially moving a strided store (A) after any load or store (B)
// that A precedes.
//
// It's legal to reorder A and B if we know there isn't a dependence from A
// to B. Note that this determination is conservative since some
// dependences could potentially be reordered safely.
// A is potentially the source of a dependence.
auto *Src = A->first;
auto SrcDes = A->second;
// B is potentially the sink of a dependence.
auto *Sink = B->first;
auto SinkDes = B->second;
// Code motion for interleaved accesses can't violate WAR dependences.
// Thus, reordering is legal if the source isn't a write.
if (!Src->mayWriteToMemory())
return true;
// At least one of the accesses must be strided.
if (!isStrided(SrcDes.Stride) && !isStrided(SinkDes.Stride))
return true;
// If dependence information is not available from LoopAccessInfo,
// conservatively assume the instructions can't be reordered.
if (!areDependencesValid())
return false;
// If we know there is a dependence from source to sink, assume the
// instructions can't be reordered. Otherwise, reordering is legal.
return !Dependences.count(Src) || !Dependences.lookup(Src).count(Sink);
}
/// \brief Collect the dependences from LoopAccessInfo.
///
/// We process the dependences once during the interleaved access analysis to
/// enable constant-time dependence queries.
void collectDependences() {
if (!areDependencesValid())
return;
auto *Deps = LAI->getDepChecker().getDependences();
for (auto Dep : *Deps)
Dependences[Dep.getSource(*LAI)].insert(Dep.getDestination(*LAI));
}
};
/// Utility class for getting and setting loop vectorizer hints in the form
/// of loop metadata.
/// This class keeps a number of loop annotations locally (as member variables)
/// and can, upon request, write them back as metadata on the loop. It will
/// initially scan the loop for existing metadata, and will update the local
/// values based on information in the loop.
/// We cannot write all values to metadata, as the mere presence of some info,
/// for example 'force', means a decision has been made. So, we need to be
/// careful NOT to add them if the user hasn't specifically asked so.
class LoopVectorizeHints {
enum HintKind {
HK_WIDTH,
HK_UNROLL,
HK_FORCE,
HK_STYLE
};
/// Hint - associates name and validation with the hint value.
struct Hint {
const char *Name;
unsigned Value; // This may have to change for non-numeric values.
HintKind Kind;
Hint(const char *Name, unsigned Value, HintKind Kind)
: Name(Name), Value(Value), Kind(Kind) {}
bool validate(unsigned Val) {
switch (Kind) {
case HK_WIDTH:
return isPowerOf2_32(Val) && Val <= VectorizerParams::MaxVectorWidth;
case HK_UNROLL:
return isPowerOf2_32(Val) && Val <= MaxInterleaveFactor;
case HK_FORCE:
return Val <= 1;
case HK_STYLE:
return Val <= 2;
}
return false;
}
};
/// Vectorization width.
Hint Width;
/// Vectorization interleave factor.
Hint Interleave;
/// Vectorization forced.
Hint Force;
/// Vectorization style (fixed/scaled vector width).
Hint Style;
/// Return the loop metadata prefix.
static StringRef Prefix() { return "llvm.loop."; }
/// True if there is any unsafe math in the loop.
bool PotentiallyUnsafe;
public:
enum ForceKind {
FK_Undefined = -1, ///< Not selected.
FK_Disabled = 0, ///< Forcing disabled.
FK_Enabled = 1 ///< Forcing enabled.
};
enum StyleKind {
SK_Unspecified = 0,
SK_Fixed = 1, ///< Forcing fixed width vectorization.
SK_Scaled = 2 ///< Forcing scalable vectorization.
};
LoopVectorizeHints(const Loop *L, bool DisableInterleaving,
OptimizationRemarkEmitter &ORE)
: Width("vectorize.width", VectorizerParams::VectorizationFactor,
HK_WIDTH),
Interleave("interleave.count", DisableInterleaving, HK_UNROLL),
Force("vectorize.enable", FK_Undefined, HK_FORCE),
Style("vectorize.style", SK_Unspecified, HK_STYLE),
PotentiallyUnsafe(false), TheLoop(L), ORE(ORE) {
// Populate values with existing loop metadata.
getHintsFromMetadata();
// force-vector-interleave overrides DisableInterleaving.
if (VectorizerParams::isInterleaveForced())
Interleave.Value = VectorizerParams::VectorizationInterleave;
DEBUG(if (DisableInterleaving && Interleave.Value == 1) dbgs()
<< "LV: Interleaving disabled by the pass manager\n");
}
/// Mark the loop L as already vectorized by setting the width to 1.
void setAlreadyVectorized() {
Width.Value = Interleave.Value = 1;
Hint Hints[] = {Width, Interleave};
writeHintsToMetadata(Hints);
}
bool allowVectorization(Function *F, Loop *L, bool AlwaysVectorize) const {
if (getForce() == LoopVectorizeHints::FK_Disabled) {
DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n");
emitRemarkWithHints();
return false;
}
if (!AlwaysVectorize && getForce() != LoopVectorizeHints::FK_Enabled) {
DEBUG(dbgs() << "LV: Not vectorizing: No #pragma vectorize enable.\n");
emitRemarkWithHints();
return false;
}
if (getWidth() == 1 && getInterleave() == 1) {
// FIXME: Add a separate metadata to indicate when the loop has already
// been vectorized instead of setting width and count to 1.
DEBUG(dbgs() << "LV: Not vectorizing: Disabled/already vectorized.\n");
// FIXME: Add interleave.disable metadata. This will allow
// vectorize.disable to be used without disabling the pass and errors
// to differentiate between disabled vectorization and a width of 1.
emitOptimizationRemarkAnalysis(
F->getContext(), vectorizeAnalysisPassName(), *F, L->getStartLoc(),
"loop not vectorized: vectorization and interleaving are explicitly "
"disabled, or vectorize width and interleave count are both set to "
"1");
return false;
}
return true;
}
/// Dumps all the hint information.
void emitRemarkWithHints() const {
using namespace ore;
if (Force.Value == LoopVectorizeHints::FK_Disabled)
ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled",
TheLoop->getStartLoc(),
TheLoop->getHeader())
<< "loop not vectorized: vectorization is explicitly disabled");
else {
OptimizationRemarkMissed R(LV_NAME, "MissedDetails",
TheLoop->getStartLoc(), TheLoop->getHeader());
R << "loop not vectorized";
if (Force.Value == LoopVectorizeHints::FK_Enabled) {
R << " (Force=" << NV("Force", true);
if (Style.Value == LoopVectorizeHints::SK_Fixed)
R << ", Style=fixed";
else if (Style.Value == LoopVectorizeHints::SK_Scaled)
R << ", Style=scaled";
if (Width.Value != 0)
R << ", Vector Width=" << NV("VectorWidth", Width.Value);
if (Interleave.Value != 0)
R << ", Interleave Count=" << NV("InterleaveCount", Interleave.Value);
R << ")";
}
ORE.emit(R);
}
}
unsigned getWidth() const { return Width.Value; }
unsigned getInterleave() const { return Interleave.Value; }
enum ForceKind getForce() const { return (ForceKind)Force.Value; }
unsigned getStyle() const { return Style.Value; }
/// \brief If hints are provided that force vectorization, use the AlwaysPrint
/// pass name to force the frontend to print the diagnostic.
const char *vectorizeAnalysisPassName() const {
if (getWidth() == 1)
return LV_NAME;
if (getForce() == LoopVectorizeHints::FK_Disabled)
return LV_NAME;
if (getForce() == LoopVectorizeHints::FK_Undefined && getWidth() == 0)
return LV_NAME;
return OptimizationRemarkAnalysis::AlwaysPrint;
}
bool allowReordering() const {
// When enabling loop hints are provided we allow the vectorizer to change
// the order of operations that is given by the scalar loop. This is not
// enabled by default because can be unsafe or inefficient. For example,
// reordering floating-point operations will change the way round-off
// error accumulates in the loop.
return getForce() == LoopVectorizeHints::FK_Enabled || getWidth() > 1;
}
bool isPotentiallyUnsafe() const {
// Avoid FP vectorization if the target is unsure about proper support.
// This may be related to the SIMD unit in the target not handling
// IEEE 754 FP ops properly, or bad single-to-double promotions.
// Otherwise, a sequence of vectorized loops, even without reduction,
// could lead to different end results on the destination vectors.
return getForce() != LoopVectorizeHints::FK_Enabled && PotentiallyUnsafe;
}
void setPotentiallyUnsafe() { PotentiallyUnsafe = true; }
private:
/// Find hints specified in the loop metadata and update local values.
void getHintsFromMetadata() {
MDNode *LoopID = TheLoop->getLoopID();
if (!LoopID)
return;
// First operand should refer to the loop id itself.
assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
const MDString *S = nullptr;
SmallVector<Metadata *, 4> Args;
// The expected hint is either a MDString or a MDNode with the first
// operand a MDString.
if (const MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i))) {
if (!MD || MD->getNumOperands() == 0)
continue;
S = dyn_cast<MDString>(MD->getOperand(0));
for (unsigned i = 1, ie = MD->getNumOperands(); i < ie; ++i)
Args.push_back(MD->getOperand(i));
} else {
S = dyn_cast<MDString>(LoopID->getOperand(i));
assert(Args.size() == 0 && "too many arguments for MDString");
}
if (!S)
continue;
// Check if the hint starts with the loop metadata prefix.
StringRef Name = S->getString();
if (Args.size() == 1)
setHint(Name, Args[0]);
}
}
/// Checks string hint with one operand and set value if valid.
void setHint(StringRef Name, Metadata *Arg) {
if (!Name.startswith(Prefix()))
return;
Name = Name.substr(Prefix().size(), StringRef::npos);
const ConstantInt *C = mdconst::dyn_extract<ConstantInt>(Arg);
if (!C)
return;
unsigned Val = C->getZExtValue();
Hint *Hints[] = {&Width, &Style, &Interleave, &Force};
for (auto H : Hints) {
if (Name == H->Name) {
if (H->validate(Val))
H->Value = Val;
else
DEBUG(dbgs() << "LV: ignoring invalid hint '" << Name << "'\n");
break;
}
}
}
/// Create a new hint from name / value pair.
MDNode *createHintMetadata(StringRef Name, unsigned V) const {
LLVMContext &Context = TheLoop->getHeader()->getContext();
Metadata *MDs[] = {MDString::get(Context, Name),
ConstantAsMetadata::get(
ConstantInt::get(Type::getInt32Ty(Context), V))};
return MDNode::get(Context, MDs);
}
/// Matches metadata with hint name.
bool matchesHintMetadataName(MDNode *Node, ArrayRef<Hint> HintTypes) {
MDString *Name = dyn_cast<MDString>(Node->getOperand(0));
if (!Name)
return false;
for (auto H : HintTypes)
if (Name->getString().endswith(H.Name))
return true;
return false;
}
/// Sets current hints into loop metadata, keeping other values intact.
void writeHintsToMetadata(ArrayRef<Hint> HintTypes) {
if (HintTypes.size() == 0)
return;
// Reserve the first element to LoopID (see below).
SmallVector<Metadata *, 4> MDs(1);
// If the loop already has metadata, then ignore the existing operands.
MDNode *LoopID = TheLoop->getLoopID();
if (LoopID) {
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
MDNode *Node = cast<MDNode>(LoopID->getOperand(i));
// If node in update list, ignore old value.
if (!matchesHintMetadataName(Node, HintTypes))
MDs.push_back(Node);
}
}
// Now, add the missing hints.
for (auto H : HintTypes)
MDs.push_back(createHintMetadata(Twine(Prefix(), H.Name).str(), H.Value));
// Replace current metadata node with new one.
LLVMContext &Context = TheLoop->getHeader()->getContext();
MDNode *NewLoopID = MDNode::get(Context, MDs);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);
TheLoop->setLoopID(NewLoopID);
}
/// The loop these hints belong to.
const Loop *TheLoop;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter &ORE;
};
static void emitMissedWarning(Function *F, Loop *L,
const LoopVectorizeHints &LH,
OptimizationRemarkEmitter *ORE) {
LH.emitRemarkWithHints();
if (LH.getForce() == LoopVectorizeHints::FK_Enabled) {
if (LH.getWidth() != 1)
ORE->emit(DiagnosticInfoOptimizationFailure(
DEBUG_TYPE, "FailedRequestedVectorization",
{L->getLocRange().getStart(), L->getLocRange().getEnd()},
L->getHeader())
<< "loop not vectorized: "
<< "failed explicitly specified loop vectorization");
else if (LH.getInterleave() != 1)
ORE->emit(DiagnosticInfoOptimizationFailure(
DEBUG_TYPE, "FailedRequestedInterleaving",
{L->getLocRange().getStart(), L->getLocRange().getEnd()},
L->getHeader())
<< "loop not interleaved: "
<< "failed explicitly specified loop interleaving");
}
}
/// LoopVectorizationLegality checks if it is legal to vectorize a loop, and
/// to what vectorization factor.
/// This class does not look at the profitability of vectorization, only the
/// legality. This class has two main kinds of checks:
/// * Memory checks - The code in canVectorizeMemory checks if vectorization
/// will change the order of memory accesses in a way that will change the
/// correctness of the program.
/// * Scalars checks - The code in canVectorizeInstrs and canVectorizeMemory
/// checks for a number of different conditions, such as the availability of a
/// single induction variable, that all types are supported and vectorize-able,
/// etc. This code reflects the capabilities of InnerLoopVectorizer.
/// This class is also used by InnerLoopVectorizer for identifying
/// induction variable and the different reduction variables.
class LoopVectorizationLegality {
public:
LoopVectorizationLegality(
Loop *L, PredicatedScalarEvolution &PSE, DominatorTree *DT,
TargetLibraryInfo *TLI, AliasAnalysis *AA, Function *F,
const TargetTransformInfo *TTI,
std::function<const LoopAccessInfo &(Loop &)> *GetLAA, LoopInfo *LI,
OptimizationRemarkEmitter *ORE, LoopVectorizationRequirements *R,
LoopVectorizeHints *H)
: NumPredStores(0), TheLoop(L), PSE(PSE), TLI(TLI), TTI(TTI), DT(DT),
GetLAA(GetLAA), LAI(nullptr), ORE(ORE), InterleaveInfo(PSE, L, DT, LI),
PrimaryInduction(nullptr), WidestIndTy(nullptr), HasFunNoNaNAttr(false),
Requirements(R), Hints(H) {}
/// Returns true if the function has an attribute saying that
/// we can assume the absence of NaNs.
bool hasNoNaNAttr(void) const { return HasFunNoNaNAttr; }
/// ReductionList contains the reduction descriptors for all
/// of the reductions that were found in the loop.
typedef DenseMap<PHINode *, RecurrenceDescriptor> ReductionList;
/// InductionList saves induction variables and maps them to the
/// induction descriptor.
typedef MapVector<PHINode *, InductionDescriptor> InductionList;
/// RecurrenceSet contains the phi nodes that are recurrences other than
/// inductions and reductions.
typedef SmallPtrSet<const PHINode *, 8> RecurrenceSet;
/// Returns true if it is legal to vectorize this loop.
/// This does not mean that it is profitable to vectorize this
/// loop, only that it is legal to do so.
bool canVectorize();
/// Returns the primary induction variable.
PHINode *getPrimaryInduction() { return PrimaryInduction; }
/// Returns the reduction variables found in the loop.
ReductionList *getReductionVars() { return &Reductions; }
/// Checks if all reduction can be performed using ordered intrinsics in
/// the loop body (e.g. using '@llvm.aarch64.sve.adda.' intrinsic).
bool allReductionsAreStrict() const {
for (auto RedP : Reductions)
if (!RedP.second.isOrdered())
return false;
return true;
}
/// Returns the induction variables found in the loop.
InductionList *getInductionVars() { return &Inductions; }
/// Return the first-order recurrences found in the loop.
RecurrenceSet *getFirstOrderRecurrences() { return &FirstOrderRecurrences; }
/// Return the set of instructions to sink to handle first-order recurrences.
DenseMap<Instruction *, Instruction *> &getSinkAfter() { return SinkAfter; }
/// Returns the widest induction type.
Type *getWidestInductionType() { return WidestIndTy; }
/// Returns True if V is an induction variable in this loop.
bool isInductionVariable(const Value *V);
/// Returns True if PN is a reduction variable in this loop.
bool isReductionVariable(PHINode *PN) { return Reductions.count(PN); }
/// Returns True if Phi is a first-order recurrence in this loop.
bool isFirstOrderRecurrence(const PHINode *Phi);
/// Return true if the block BB needs to be predicated in order for the loop
/// to be vectorized.
bool blockNeedsPredication(BasicBlock *BB);
/// Check if this pointer is consecutive when vectorizing. This happens
/// when the last index of the GEP is the induction variable, or that the
/// pointer itself is an induction variable.
/// This check allows us to vectorize A[idx] into a wide load/store.
/// Returns:
/// 0 - Stride is unknown or non-consecutive.
/// 1 - Address is consecutive.
/// -1 - Address is consecutive, and decreasing.
int isConsecutivePtr(Value *Ptr);
/// Returns true if the value V is uniform within the loop.
bool isUniform(Value *V);
/// Returns true if this instruction will remain scalar after vectorization.
bool isUniformAfterVectorization(Instruction *I) { return Uniforms.count(I); }
/// Returns the information that we collected about runtime memory check.
const RuntimePointerChecking *getRuntimePointerChecking() const {
return LAI->getRuntimePointerChecking();
}
const LoopAccessInfo *getLAI() const { return LAI; }
/// \brief Check if \p Instr belongs to any interleaved access group.
bool isAccessInterleaved(Instruction *Instr) {
return InterleaveInfo.isInterleaved(Instr);
}
/// \brief Return the maximum interleave factor of all interleaved groups.
unsigned getMaxInterleaveFactor() const {
return InterleaveInfo.getMaxInterleaveFactor();
}
/// \brief Get the interleaved access group that \p Instr belongs to.
const InterleaveGroup *getInterleavedAccessGroup(Instruction *Instr) {
return InterleaveInfo.getInterleaveGroup(Instr);
}
/// \brief Returns true if an interleaved group requires a scalar iteration
/// to handle accesses with gaps.
bool requiresScalarEpilogue() const {
return InterleaveInfo.requiresScalarEpilogue();
}
unsigned getMaxSafeDepDistBytes() { return LAI->getMaxSafeDepDistBytes(); }
bool hasStride(Value *V) { return StrideSet.count(V); }
bool mustCheckStrides() { return !StrideSet.empty(); }
SmallPtrSet<Value *, 8>::iterator strides_begin() {
return StrideSet.begin();
}
SmallPtrSet<Value *, 8>::iterator strides_end() { return StrideSet.end(); }
/// Returns true if the target machine supports masked store operation
/// for the given \p DataType and kind of access to \p Ptr.
bool isLegalMaskedStore(Type *DataType, Value *Ptr) {
return isConsecutivePtr(Ptr) && TTI->isLegalMaskedStore(DataType);
}
/// Returns true if the target machine supports masked load operation
/// for the given \p DataType and kind of access to \p Ptr.
bool isLegalMaskedLoad(Type *DataType, Value *Ptr) {
return isConsecutivePtr(Ptr) && TTI->isLegalMaskedLoad(DataType);
}
/// Returns true if the target machine supports masked scatter operation
/// for the given \p DataType.
bool isLegalMaskedScatter(Type *DataType) {
return TTI->isLegalMaskedScatter(DataType);
}
/// Returns true if the target machine supports masked gather operation
/// for the given \p DataType.
bool isLegalMaskedGather(Type *DataType) {
return TTI->isLegalMaskedGather(DataType);
}
/// Returns true if the target machine can represent \p V as a masked gather
/// or scatter operation.
bool isLegalGatherOrScatter(Value *V) {
auto *LI = dyn_cast<LoadInst>(V);
auto *SI = dyn_cast<StoreInst>(V);
if (!LI && !SI)
return false;
auto *Ptr = getPointerOperand(V);
auto *Ty = cast<PointerType>(Ptr->getType())->getElementType();
return (LI && isLegalMaskedGather(Ty)) || (SI && isLegalMaskedScatter(Ty));
}
/// Returns true if vector representation of the instruction \p I
/// requires mask.
bool isMaskRequired(const Instruction *I) { return (MaskedOp.count(I) != 0); }
/// Returns true if the loop requires masked operations for vectorisation to
/// be legal.
bool hasMaskedOperations() { return MaskedOp.begin() != MaskedOp.end(); }
unsigned getNumStores() const { return LAI->getNumStores(); }
unsigned getNumLoads() const { return LAI->getNumLoads(); }
unsigned getNumPredStores() const { return NumPredStores; }
private:
/// Check if a single basic block loop is vectorizable.
/// At this point we know that this is a loop with a constant trip count
/// and we only need to check individual instructions.
bool canVectorizeInstrs();
/// When we vectorize loops we may change the order in which
/// we read and write from memory. This method checks if it is
/// legal to vectorize the code, considering only memory constrains.
/// Returns true if the loop is vectorizable
bool canVectorizeMemory();
/// Return true if we can vectorize this loop using the IF-conversion
/// transformation.
bool canVectorizeWithIfConvert();
/// Collect the variables that need to stay uniform after vectorization.
void collectLoopUniforms();
/// Return true if all of the instructions in the block can be speculatively
/// executed. \p SafePtrs is a list of addresses that are known to be legal
/// and we know that we can read from them without segfault.
bool blockCanBePredicated(BasicBlock *BB, SmallPtrSetImpl<Value *> &SafePtrs);
/// \brief Collect memory access with loop invariant strides.
///
/// Looks for accesses like "a[i * StrideA]" where "StrideA" is loop
/// invariant.
void collectStridedAccess(Value *LoadOrStoreInst);
/// Updates the vectorization state by adding \p Phi to the inductions list.
/// This can set \p Phi as the main induction of the loop if \p Phi is a
/// better choice for the main induction than the existing one.
void addInductionPhi(PHINode *Phi, const InductionDescriptor &ID,
SmallPtrSetImpl<Value *> &AllowedExit);
/// Create an analysis remark that explains why vectorization failed
///
/// \p RemarkName is the identifier for the remark. If \p I is passed it is
/// an instruction that prevents vectorization. Otherwise the loop is used
/// for the location of the remark. \return the remark object that can be
/// streamed to.
OptimizationRemarkAnalysis
createMissedAnalysis(StringRef RemarkName, Instruction *I = nullptr) const {
return ::createMissedAnalysis(Hints->vectorizeAnalysisPassName(),
RemarkName, TheLoop, I);
}
unsigned NumPredStores;
/// The loop that we evaluate.
Loop *TheLoop;
/// A wrapper around ScalarEvolution used to add runtime SCEV checks.
/// Applies dynamic knowledge to simplify SCEV expressions in the context
/// of existing SCEV assumptions. The analysis will also add a minimal set
/// of new predicates if this is required to enable vectorization and
/// unrolling.
PredicatedScalarEvolution &PSE;
/// Target Library Info.
TargetLibraryInfo *TLI;
/// Parent function
Function *TheFunction;
/// Target Transform Info
const TargetTransformInfo *TTI;
/// Dominator Tree.
DominatorTree *DT;
// LoopAccess analysis.
std::function<const LoopAccessInfo &(Loop &)> *GetLAA;
// And the loop-accesses info corresponding to this loop. This pointer is
// null until canVectorizeMemory sets it up.
const LoopAccessInfo *LAI;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter *ORE;
/// The interleave access information contains groups of interleaved accesses
/// with the same stride and close to each other.
InterleavedAccessInfo InterleaveInfo;
// --- vectorization state --- //
/// Holds the primary induction variable. This is the counter of the
/// loop.
PHINode *PrimaryInduction;
/// Holds the reduction variables.
ReductionList Reductions;
/// Holds all of the induction variables that we found in the loop.
/// Notice that inductions don't need to start at zero and that induction
/// variables can be pointers.
InductionList Inductions;
/// Holds the phi nodes that are first-order recurrences.
RecurrenceSet FirstOrderRecurrences;
/// Holds instructions that need to sink past other instructions to handle
/// first-order recurrences.
DenseMap<Instruction *, Instruction *> SinkAfter;
/// Holds the widest induction type encountered.
Type *WidestIndTy;
/// Allowed outside users. This holds the reduction
/// vars which can be accessed from outside the loop.
SmallPtrSet<Value *, 4> AllowedExit;
/// This set holds the variables which are known to be uniform after
/// vectorization.
SmallPtrSet<Instruction *, 4> Uniforms;
/// Can we assume the absence of NaNs.
bool HasFunNoNaNAttr;
/// Vectorization requirements that will go through late-evaluation.
LoopVectorizationRequirements *Requirements;
/// Used to emit an analysis of any legality issues.
LoopVectorizeHints *Hints;
ValueToValueMap Strides;
SmallPtrSet<Value *, 8> StrideSet;
/// While vectorizing these instructions we have to generate a
/// call to the appropriate masked intrinsic
SmallPtrSet<const Instruction *, 8> MaskedOp;
/// If enabled, we will vectorize (some) loops which do not have
/// a defined trip count that SCEV can determine.
bool AllowUncounted;
};
/// LoopVectorizationCostModel - estimates the expected speedups due to
/// vectorization.
/// In many cases vectorization is not profitable. This can happen because of
/// a number of reasons. In this class we mainly attempt to predict the
/// expected speedup/slowdowns due to the supported instruction set. We use the
/// TargetTransformInfo to query the different backends for the cost of
/// different operations.
class LoopVectorizationCostModel {
public:
LoopVectorizationCostModel(Loop *L, PredicatedScalarEvolution &PSE,
LoopInfo *LI, LoopVectorizationLegality *Legal,
const TargetTransformInfo &TTI,
const TargetLibraryInfo *TLI, DemandedBits *DB,
AssumptionCache *AC,
OptimizationRemarkEmitter *ORE, const Function *F,
const LoopVectorizeHints *Hints)
: TheLoop(L), PSE(PSE), LI(LI), Legal(Legal), TTI(TTI), TLI(TLI), DB(DB),
AC(AC), ORE(ORE), TheFunction(F), Hints(Hints) {}
/// \return The most profitable vectorization factor and the cost of that VF.
/// This method checks every power of two up to VF. If UserVF is not ZERO
/// then this vectorization factor will be selected if vectorization is
/// possible.
VectorizationFactor selectVectorizationFactor(bool OptForSize);
/// \return The size (in bits) of the smallest and widest types in the code
/// that needs to be vectorized. We ignore values that remain scalar such as
/// 64 bit loop indices.
std::pair<unsigned, unsigned> getSmallestAndWidestTypes();
/// \return The desired interleave count.
/// If interleave count has been specified by metadata it will be returned.
/// Otherwise, the interleave count is computed and returned. VF and LoopCost
/// are the selected vectorization factor and the cost of the selected VF.
unsigned selectInterleaveCount(bool OptForSize, VectorizationFactor VF,
unsigned LoopCost);
/// \return The most profitable unroll factor.
/// This method finds the best unroll-factor based on register pressure and
/// other parameters. VF and LoopCost are the selected vectorization factor
/// and the cost of the selected VF.
unsigned computeInterleaveCount(bool OptForSize, VectorizationFactor VF,
unsigned LoopCost);
/// \brief A struct that represents some properties of the register usage
/// of a loop.
struct RegisterUsage {
/// Holds the number of loop invariant values that are used in the loop.
unsigned LoopInvariantRegs;
/// Holds the maximum number of concurrent live intervals in the loop.
unsigned MaxLocalUsers;
/// Holds the number of instructions in the loop.
unsigned NumInstructions;
};
/// \return Returns information about the register usages of the loop for the
/// given vectorization factors.
SmallVector<RegisterUsage, 8> calculateRegisterUsage(ArrayRef<unsigned> VFs);
/// Collect values we want to ignore in the cost model.
void collectValuesToIgnore();
private:
/// The vectorization cost is a combination of the cost itself and a boolean
/// indicating whether any of the contributing operations will actually
/// operate on vector values after type legalization in the backend. If this
/// latter value is false, then all operations will be scalarized
/// (i.e. no vectorization has actually taken place).
typedef std::pair<unsigned, bool> VectorizationCostTy;
/// Returns the expected execution cost. The unit of the cost does
/// not matter because we use the 'cost' units to compare different
/// vector widths. The cost that is returned is *not* normalized by
/// the factor width.
VectorizationCostTy expectedCost(VectorizationFactor VF);
/// Returns the execution time cost of an instruction for a given vector
/// width. Vector width of one means scalar.
VectorizationCostTy getInstructionCost(Instruction *I,
VectorizationFactor VF);
/// The cost-computation logic from getInstructionCost which provides
/// the vector type as an output parameter.
unsigned getInstructionCost(Instruction *I, VectorizationFactor VF,
Type *&VectorTy);
/// Returns whether the instruction is a load or store and will be a emitted
/// as a vector operation.
bool isConsecutiveLoadOrStore(Instruction *I);
/// Create an analysis remark that explains why vectorization failed
///
/// \p RemarkName is the identifier for the remark. \return the remark object
/// that can be streamed to.
OptimizationRemarkAnalysis createMissedAnalysis(StringRef RemarkName) {
return ::createMissedAnalysis(Hints->vectorizeAnalysisPassName(),
RemarkName, TheLoop);
}
public:
/// Map of scalar integer values to the smallest bitwidth they can be legally
/// represented as. The vector equivalents of these values should be truncated
/// to this type.
MapVector<Instruction *, uint64_t> MinBWs;
/// The loop that we evaluate.
Loop *TheLoop;
/// Predicated scalar evolution analysis.
PredicatedScalarEvolution &PSE;
/// Loop Info analysis.
LoopInfo *LI;
/// Vectorization legality.
LoopVectorizationLegality *Legal;
/// Vector target information.
const TargetTransformInfo &TTI;
/// Target Library Info.
const TargetLibraryInfo *TLI;
/// Demanded bits analysis.
DemandedBits *DB;
/// Assumption cache.
AssumptionCache *AC;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter *ORE;
const Function *TheFunction;
/// Loop Vectorize Hint.
const LoopVectorizeHints *Hints;
/// Values to ignore in the cost model.
SmallPtrSet<const Value *, 16> ValuesToIgnore;
/// Values to ignore in the cost model when VF > 1.
SmallPtrSet<const Value *, 16> VecValuesToIgnore;
};
/// \brief This holds vectorization requirements that must be verified late in
/// the process. The requirements are set by legalize and costmodel. Once
/// vectorization has been determined to be possible and profitable the
/// requirements can be verified by looking for metadata or compiler options.
/// For example, some loops require FP commutativity which is only allowed if
/// vectorization is explicitly specified or if the fast-math compiler option
/// has been provided.
/// Late evaluation of these requirements allows helpful diagnostics to be
/// composed that tells the user what need to be done to vectorize the loop. For
/// example, by specifying #pragma clang loop vectorize or -ffast-math. Late
/// evaluation should be used only when diagnostics can generated that can be
/// followed by a non-expert user.
class LoopVectorizationRequirements {
public:
LoopVectorizationRequirements(OptimizationRemarkEmitter &ORE)
: NumRuntimePointerChecks(0), UnsafeAlgebraInst(nullptr), ORE(ORE) {}
void addUnsafeAlgebraInst(Instruction *I) {
// First unsafe algebra instruction.
if (!UnsafeAlgebraInst)
UnsafeAlgebraInst = I;
}
void addRuntimePointerChecks(unsigned Num) { NumRuntimePointerChecks = Num; }
bool doesNotMeet(Function *F, Loop *L, const LoopVectorizeHints &Hints,
const LoopVectorizationLegality &LVL) {
const char *PassName = Hints.vectorizeAnalysisPassName();
bool Failed = false;
if (UnsafeAlgebraInst && !Hints.allowReordering()) {
if (LVL.allReductionsAreStrict()) {
DEBUG(dbgs() << "LV: Vectorization possible with ordered reduction\n");
} else {
ORE.emit(
OptimizationRemarkAnalysisFPCommute(PassName, "CantReorderFPOps",
UnsafeAlgebraInst->getDebugLoc(),
UnsafeAlgebraInst->getParent())
<< "loop not vectorized: cannot prove it is safe to reorder "
"floating-point operations");
Failed = true;
}
}
// Test if runtime memcheck thresholds are exceeded.
bool PragmaThresholdReached =
NumRuntimePointerChecks > PragmaVectorizeMemoryCheckThreshold;
bool ThresholdReached =
NumRuntimePointerChecks > VectorizerParams::RuntimeMemoryCheckThreshold;
if ((ThresholdReached && !Hints.allowReordering()) ||
PragmaThresholdReached) {
ORE.emit(OptimizationRemarkAnalysisAliasing(PassName, "CantReorderMemOps",
L->getStartLoc(),
L->getHeader())
<< "loop not vectorized: cannot prove it is safe to reorder "
"memory operations");
DEBUG(dbgs() << "LV: Too many memory checks needed.\n");
Failed = true;
}
return Failed;
}
private:
unsigned NumRuntimePointerChecks;
Instruction *UnsafeAlgebraInst;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter &ORE;
};
static void addAcyclicInnerLoop(Loop &L, SmallVectorImpl<Loop *> &V) {
if (L.empty()) {
if (!hasCyclesInLoopBody(L))
V.push_back(&L);
return;
}
for (Loop *InnerL : L)
addAcyclicInnerLoop(*InnerL, V);
}
/// The SVELoopVectorize Pass.
struct SVELoopVectorize : public FunctionPass {
/// Pass identification, replacement for typeid
static char ID;
explicit SVELoopVectorize(bool NoUnrolling = false, bool AlwaysVectorize = true)
: FunctionPass(ID), DisableUnrolling(NoUnrolling),
AlwaysVectorize(AlwaysVectorize) {
initializeSVELoopVectorizePass(*PassRegistry::getPassRegistry());
}
ScalarEvolution *SE;
LoopInfo *LI;
TargetTransformInfo *TTI;
DominatorTree *DT;
BlockFrequencyInfo *BFI;
TargetLibraryInfo *TLI;
DemandedBits *DB;
AliasAnalysis *AA;
AssumptionCache *AC;
LoopAccessLegacyAnalysis *LAA;
bool DisableUnrolling;
bool AlwaysVectorize;
OptimizationRemarkEmitter *ORE;
BlockFrequency ColdEntryFreq;
bool runOnFunction(Function &F) override {
if (skipFunction(F))
return false;
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
BFI = &getAnalysis<BlockFrequencyInfoWrapperPass>().getBFI();
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
TLI = TLIP ? &TLIP->getTLI() : nullptr;
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
DB = &getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
// Compute some weights outside of the loop over the loops. Compute this
// using a BranchProbability to re-use its scaling math.
const BranchProbability ColdProb(1, 5); // 20%
ColdEntryFreq = BlockFrequency(BFI->getEntryFreq()) * ColdProb;
// Don't attempt if
// 1. the target claims to have no vector registers, and
// 2. interleaving won't help ILP.
//
// The second condition is necessary because, even if the target has no
// vector registers, loop vectorization may still enable scalar
// interleaving.
if (!TTI->getNumberOfRegisters(true) && TTI->getMaxInterleaveFactor(1) < 2)
return false;
bool Changed = false;
// The vectorizer requires loops to be in simplified form.
// Since simplification may add new inner loops, it has to run before the
// legality and profitability checks. This means running the loop vectorizer
// will simplify all loops, regardless of whether anything end up being
// vectorized.
for (auto &L : *LI)
Changed |= simplifyLoop(L, DT, LI, SE, AC, false /* PreserveLCSSA */);
// Build up a worklist of inner-loops to vectorize. This is necessary as
// the act of vectorizing or partially unrolling a loop creates new loops
// and can invalidate iterators across the loops.
SmallVector<Loop *, 8> Worklist;
for (Loop *L : *LI)
addAcyclicInnerLoop(*L, Worklist);
LoopsAnalyzed += Worklist.size();
// Now walk the identified inner loops.
while (!Worklist.empty()) {
Loop *L = Worklist.pop_back_val();
// For the inner loops we actually process, form LCSSA to simplify the
// transform.
Changed |= formLCSSARecursively(*L, *DT, LI, SE);
Changed |= processLoop(L);
}
// Process each loop nest in the function.
return Changed;
}
static void AddRuntimeUnrollDisableMetaData(Loop *L) {
SmallVector<Metadata *, 4> MDs;
// Reserve first location for self reference to the LoopID metadata node.
MDs.push_back(nullptr);
bool IsUnrollMetadata = false;
MDNode *LoopID = L->getLoopID();
if (LoopID) {
// First find existing loop unrolling disable metadata.
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
if (MD) {
const MDString *S = dyn_cast<MDString>(MD->getOperand(0));
IsUnrollMetadata =
S && S->getString().startswith("llvm.loop.unroll.disable");
}
MDs.push_back(LoopID->getOperand(i));
}
}
if (!IsUnrollMetadata) {
// Add runtime unroll disable metadata.
LLVMContext &Context = L->getHeader()->getContext();
SmallVector<Metadata *, 1> DisableOperands;
DisableOperands.push_back(
MDString::get(Context, "llvm.loop.unroll.runtime.disable"));
MDNode *DisableNode = MDNode::get(Context, DisableOperands);
MDs.push_back(DisableNode);
MDNode *NewLoopID = MDNode::get(Context, MDs);
// Set operand 0 to refer to the loop id itself.
NewLoopID->replaceOperandWith(0, NewLoopID);
L->setLoopID(NewLoopID);
}
}
bool processLoop(Loop *L) {
assert(L->empty() && "Only process inner loops.");
#ifndef NDEBUG
const std::string DebugLocStr = getDebugLocString(L);
#endif /* NDEBUG */
DEBUG(dbgs() << "\nLV: Checking a loop in \""
<< L->getHeader()->getParent()->getName() << "\" from "
<< DebugLocStr << "\n");
LoopVectorizeHints Hints(L, DisableUnrolling, *ORE);
DEBUG(dbgs() << "LV: Loop hints:"
<< " force="
<< (Hints.getForce() == LoopVectorizeHints::FK_Disabled
? "disabled"
: (Hints.getForce() == LoopVectorizeHints::FK_Enabled
? "enabled"
: "?"))
<< " width=" << Hints.getWidth()
<< " style="
<< (Hints.getStyle() == LoopVectorizeHints::SK_Fixed
? "fixed"
: (Hints.getStyle() == LoopVectorizeHints::SK_Scaled
? "scaled"
: "default"))
<< " unroll=" << Hints.getInterleave() << "\n");
// Function containing loop
Function *F = L->getHeader()->getParent();
// Looking at the diagnostic output is the only way to determine if a loop
// was vectorized (other than looking at the IR or machine code), so it
// is important to generate an optimization remark for each loop. Most of
// these messages are generated by emitOptimizationRemarkAnalysis. Remarks
// generated by emitOptimizationRemark and emitOptimizationRemarkMissed are
// less verbose reporting vectorized loops and unvectorized loops that may
// benefit from vectorization, respectively.
if (!Hints.allowVectorization(F, L, AlwaysVectorize)) {
DEBUG(dbgs() << "LV: Loop hints prevent vectorization.\n");
return false;
}
// Check the loop for a trip count threshold:
// do not vectorize loops with a tiny trip count.
const unsigned TC = SE->getSmallConstantTripCount(L);
if (TC > 0u && TC < TinyTripCountVectorThreshold) {
DEBUG(dbgs() << "LV: Found a loop with a very small trip count. "
<< "This loop is not worth vectorizing.");
if (Hints.getForce() == LoopVectorizeHints::FK_Enabled)
DEBUG(dbgs() << " But vectorizing was explicitly forced.\n");
else {
DEBUG(dbgs() << "\n");
ORE->emit(createMissedAnalysis(Hints.vectorizeAnalysisPassName(),
"NotBeneficial", L)
<< "vectorization is not beneficial "
"and is not explicitly forced");
ORE->emit(createMissedAnalysis(Hints.vectorizeAnalysisPassName(),
"NotBeneficial", L)
<< "to locally force vectorization, prefix loop with "
"\"#pragma clang loop vectorize (enable)\"");
ORE->emit(createMissedAnalysis(Hints.vectorizeAnalysisPassName(),
"NotBeneficial", L)
<< "to globally force vectorization, compile with "
"\"-mllvm -vectorizer-min-trip-count "
<< std::to_string(TC) << "\"");
return false;
}
}
PredicatedScalarEvolution PSE(*SE, *L);
std::function<const LoopAccessInfo &(Loop &)> GetLAA =
[&](Loop &L) -> const LoopAccessInfo & { return LAA->getInfo(&L); };
// Check if it is legal to vectorize the loop.
LoopVectorizationRequirements Requirements(*ORE);
LoopVectorizationLegality LVL(L, PSE, DT, TLI, AA, F, TTI, &GetLAA, LI, ORE,
&Requirements, &Hints);
if (!LVL.canVectorize()) {
DEBUG(dbgs() << "LV: Not vectorizing: Cannot prove legality.\n");
emitMissedWarning(F, L, Hints, ORE);
return false;
}
// Use the cost model.
LoopVectorizationCostModel CM(L, PSE, LI, &LVL, *TTI, TLI, DB, AC, ORE, F,
&Hints);
CM.collectValuesToIgnore();
// Check the function attributes to find out if this function should be
// optimized for size.
bool OptForSize =
Hints.getForce() != LoopVectorizeHints::FK_Enabled && F->optForSize();
// Compute the weighted frequency of this loop being executed and see if it
// is less than 20% of the function entry baseline frequency. Note that we
// always have a canonical loop here because we think we *can* vectorize.
// FIXME: This is hidden behind a flag due to pervasive problems with
// exactly what block frequency models.
if (LoopVectorizeWithBlockFrequency) {
BlockFrequency LoopEntryFreq = BFI->getBlockFreq(L->getLoopPreheader());
if (Hints.getForce() != LoopVectorizeHints::FK_Enabled &&
LoopEntryFreq < ColdEntryFreq)
OptForSize = true;
}
// Check the function attributes to see if implicit floats are allowed.
// FIXME: This check doesn't seem possibly correct -- what if the loop is
// an integer loop and the vector instructions selected are purely integer
// vector instructions?
if (F->hasFnAttribute(Attribute::NoImplicitFloat)) {
DEBUG(dbgs() << "LV: Can't vectorize when the NoImplicitFloat"
"attribute is used.\n");
ORE->emit(createMissedAnalysis(Hints.vectorizeAnalysisPassName(),
"NoImplicitFloat", L)
<< "loop not vectorized due to NoImplicitFloat attribute");
emitMissedWarning(F, L, Hints, ORE);
return false;
}
// Check if the target supports potentially unsafe FP vectorization.
// FIXME: Add a check for the type of safety issue (denormal, signaling)
// for the target we're vectorizing for, to make sure none of the
// additional fp-math flags can help.
if (Hints.isPotentiallyUnsafe() &&
TTI->isFPVectorizationPotentiallyUnsafe()) {
DEBUG(dbgs() << "LV: Potentially unsafe FP op prevents vectorization.\n");
ORE->emit(
createMissedAnalysis(Hints.vectorizeAnalysisPassName(), "UnsafeFP", L)
<< "loop not vectorized due to unsafe FP support.");
emitMissedWarning(F, L, Hints, ORE);
return false;
}
// Select the optimal vectorization factor.
const VectorizationFactor VF = CM.selectVectorizationFactor(OptForSize);
// Select the interleave count.
unsigned IC = CM.selectInterleaveCount(OptForSize, VF, VF.Cost);
// Get user interleave count.
unsigned UserIC = Hints.getInterleave();
// Identify the diagnostic messages that should be produced.
std::pair<StringRef, std::string> VecDiagMsg, IntDiagMsg;
bool VectorizeLoop = true, InterleaveLoop = true;
if (Requirements.doesNotMeet(F, L, Hints, LVL)) {
DEBUG(dbgs() << "LV: Not vectorizing: loop did not meet vectorization "
"requirements.\n");
emitMissedWarning(F, L, Hints, ORE);
return false;
}
if (VF.Width == 1) {
DEBUG(dbgs() << "LV: Vectorization is possible but not beneficial.\n");
VecDiagMsg = std::make_pair(
"VectorizationNotBeneficial",
"the cost-model indicates that vectorization is not beneficial");
VectorizeLoop = false;
}
if (IC == 1 && UserIC <= 1) {
// Tell the user interleaving is not beneficial.
DEBUG(dbgs() << "LV: Interleaving is not beneficial.\n");
IntDiagMsg = std::make_pair(
"InterleavingNotBeneficial",
"the cost-model indicates that interleaving is not beneficial");
InterleaveLoop = false;
if (UserIC == 1) {
IntDiagMsg.first = "InterleavingNotBeneficialAndDisabled";
IntDiagMsg.second +=
" and is explicitly disabled or interleave count is set to 1";
}
} else if (IC > 1 && UserIC == 1) {
// Tell the user interleaving is beneficial, but it explicitly disabled.
DEBUG(dbgs()
<< "LV: Interleaving is beneficial but is explicitly disabled.");
IntDiagMsg = std::make_pair(
"InterleavingBeneficialButDisabled",
"the cost-model indicates that interleaving is beneficial "
"but is explicitly disabled or interleave count is set to 1");
InterleaveLoop = false;
}
if (!VectorizeLoop && InterleaveLoop && LVL.hasMaskedOperations()) {
DEBUG(dbgs()
<< "LV: Interleaving is beneficial but loop contain masked access");
IntDiagMsg = std::make_pair(
"InterleavingBeneficialButContainsMaskedAccess",
"interleaving not possible because of masked accesses");
InterleaveLoop = false;
}
// Override IC if user provided an interleave count.
IC = UserIC > 0 ? UserIC : IC;
// Emit diagnostic messages, if any.
const char *VAPassName = Hints.vectorizeAnalysisPassName();
if (!VectorizeLoop && !InterleaveLoop) {
// Do not vectorize or interleaving the loop.
ORE->emit(OptimizationRemarkMissed(VAPassName, VecDiagMsg.first,
{L->getLocRange().getStart(),
L->getLocRange().getEnd()},
L->getHeader())
<< VecDiagMsg.second);
ORE->emit(OptimizationRemarkMissed(LV_NAME, IntDiagMsg.first,
{L->getLocRange().getStart(),
L->getLocRange().getEnd()},
L->getHeader())
<< IntDiagMsg.second);
return false;
} else if (!VectorizeLoop && InterleaveLoop) {
DEBUG(dbgs() << "LV: Interleave Count is " << IC << '\n');
ORE->emit(OptimizationRemarkAnalysis(VAPassName, VecDiagMsg.first,
{L->getLocRange().getStart(),
L->getLocRange().getEnd()},
L->getHeader())
<< VecDiagMsg.second);
} else if (VectorizeLoop && !InterleaveLoop) {
DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
<< DebugLocStr << '\n');
ORE->emit(OptimizationRemarkAnalysis(LV_NAME, IntDiagMsg.first,
{L->getLocRange().getStart(),
L->getLocRange().getEnd()},
L->getHeader())
<< IntDiagMsg.second);
} else if (VectorizeLoop && InterleaveLoop) {
DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
<< DebugLocStr << '\n');
DEBUG(dbgs() << "LV: Interleave Count is " << IC << '\n');
}
using namespace ore;
if (!VectorizeLoop) {
assert(IC > 1 && "interleave count should not be 1 or 0");
// If we decided that it is not legal to vectorize the loop, then
// interleave it.
InnerLoopUnroller Unroller(L, PSE, LI, DT, TLI, TTI, AC, ORE, IC);
Unroller.vectorize(&LVL, CM.MinBWs);
emitOptimizationRemark(F->getContext(), LV_NAME, *F, L->getStartLoc(),
Twine("interleaved loop (interleaved count: ") +
Twine(IC) + ")");
} else {
// If we decided that it is *legal* to vectorize the loop then do it.
InnerLoopVectorizer LB(L, PSE, LI, DT, TLI, TTI, AC, ORE, VF.Width, IC,
VF.isFixed);
LB.vectorize(&LVL, CM.MinBWs);
++LoopsVectorized;
if (LB.isScalable())
++LoopsVectorizedWA;
// Add metadata to disable runtime unrolling a scalar loop when there are
// no runtime checks about strides and memory. A scalar loop that is
// rarely used is not worth unrolling.
if (!LB.areSafetyChecksAdded())
AddRuntimeUnrollDisableMetaData(L);
// Report the vectorization decision.
OptimizationRemark R(LV_NAME, "Vectorized",
{L->getLocRange().getStart(),
L->getLocRange().getEnd()},
L->getHeader());
R << "vectorized loop (vectorization width: "
<< NV("VectorizationFactor", VF.Width)
<< ", interleaved count: " << NV("InterleaveCount", IC) << ")"
<< setExtraArgs()
<< "(runtime checks: "
<< NV("RTNeeded",
std::string(LVL.getRuntimePointerChecking()->Need ? "" : "no"))
<< ", FixedWidthVectorization: "
<< NV("FixedWidthVectorization", std::string("scaled"))
<< ")";
ORE->emit(R);
}
// Mark the loop as already vectorized to avoid vectorizing again.
Hints.setAlreadyVectorized();
DEBUG(verifyFunction(*L->getHeader()->getParent()));
return true;
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<BlockFrequencyInfoWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<ScalarEvolutionWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
AU.addRequired<AAResultsWrapperPass>();
AU.addRequired<LoopAccessLegacyAnalysis>();
AU.addRequired<DemandedBitsWrapperPass>();
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
AU.addPreserved<LoopInfoWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
AU.addPreserved<BasicAAWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
}
};
} // end anonymous namespace
//===----------------------------------------------------------------------===//
// Implementation of LoopVectorizationLegality, InnerLoopVectorizer and
// LoopVectorizationCostModel.
//===----------------------------------------------------------------------===//
Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) {
// We need to place the broadcast of invariant variables outside the loop.
Instruction *Instr = dyn_cast<Instruction>(V);
bool NewInstr =
(Instr && std::find(LoopVectorBody.begin(), LoopVectorBody.end(),
Instr->getParent()) != LoopVectorBody.end());
bool Invariant = OrigLoop->isLoopInvariant(V) && !NewInstr;
// Place the code for broadcasting invariant variables in the new preheader.
IRBuilder<>::InsertPointGuard Guard(Builder);
if (Invariant)
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
// Broadcast the scalar into all locations in the vector.
Value *Shuf = Builder.CreateVectorSplat({VF, Scalable}, V, "broadcast");
return Shuf;
}
Value *InnerLoopVectorizer::getStepVector(Value *Val, Value *Start,
const SCEV *StepSCEV,
Instruction::BinaryOps BinOp) {
const DataLayout &DL = OrigLoop->getHeader()->getModule()->getDataLayout();
SCEVExpander Exp(*PSE.getSE(), DL, "induction");
Value *StepValue = Exp.expandCodeFor(StepSCEV, StepSCEV->getType(),
&*Builder.GetInsertPoint());
return getStepVector(Val, Start, StepValue, BinOp);
}
void InnerLoopVectorizer::widenInductionVariable(const InductionDescriptor &II,
VectorParts &Entry,
IntegerType *TruncType) {
Value *Start = II.getStartValue();
ConstantInt *Step = II.getConstIntStepValue();
assert(Step && "Can not widen an IV with a non-constant step");
// Construct the initial value of the vector IV in the vector loop preheader
auto CurrIP = Builder.saveIP();
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
if (TruncType) {
Step = ConstantInt::getSigned(TruncType, Step->getSExtValue());
Start = Builder.CreateCast(Instruction::Trunc, Start, TruncType);
}
Value *SplatStart = Builder.CreateVectorSplat({VF, Scalable}, Start);
Value *SteppedStart = getStepVector(SplatStart, 0, Step);
Builder.restoreIP(CurrIP);
Value *NumEls =
getElementCount(Start->getType(), VF, Scalable, Start->getType());
Value *SplatVF = Builder.CreateVectorSplat({VF, Scalable}, NumEls);
PHINode *VecInd =
PHINode::Create(SteppedStart->getType(), 2, "vec.ind",
&*LoopVectorBody[0]->getFirstInsertionPt());
Value *LastInduction = VecInd;
for (unsigned Part = 0; Part < UF; ++Part) {
Entry[Part] = LastInduction;
LastInduction = Builder.CreateAdd(LastInduction, SplatVF, "step.add");
}
auto Latch = LI->getLoopFor(LoopVectorBody[0])->getLoopLatch();
VecInd->addIncoming(SteppedStart, LoopVectorPreHeader);
VecInd->addIncoming(LastInduction, Latch);
}
Value *InnerLoopVectorizer::getStepVector(Value *Val, int Start, Value *Step,
Instruction::BinaryOps BinOp) {
Type *Ty = Val->getType()->getScalarType();
return getStepVector(Val, ConstantInt::get(Ty, Start), Step, BinOp);
}
Value *InnerLoopVectorizer::getStepVector(Value *Val, Value *Start, Value *Step,
Instruction::BinaryOps BinOp) {
assert(Val->getType()->isVectorTy() && "Must be a vector");
assert(Step->getType() == Val->getType()->getScalarType() &&
"Step has wrong type");
VectorType *Ty = cast<VectorType>(Val->getType());
Value *One = ConstantInt::get(Start->getType(), 1);
// Create a vector of consecutive numbers from Start to Start+VF
Value *Cv = Builder.CreateSeriesVector(Ty->getElementCount(), Start, One);
Step = Builder.CreateVectorSplat(Ty->getElementCount(), Step);
if (Val->getType()->getScalarType()->isIntegerTy()) {
// Add the consecutive indices to the vector value.
assert(Cv->getType() == Val->getType() && "Invalid consecutive vec");
// FIXME: The newly created binary instructions should contain nsw/nuw
// flags, which can be found from the original scalar operations.
Step = Builder.CreateMul(Cv, Step);
return Builder.CreateAdd(Val, Step, "induction");
} else {
// Floating point induction.
assert(Val->getType()->getScalarType()->isFloatingPointTy() &&
"Elem must be an fp type");
assert((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
"Binary Opcode should be specified for FP induction");
// Cv is an integer vector, need to convert to fp.
// Floating point operations had to be 'fast' to enable the induction.
FastMathFlags Flags;
Flags.setUnsafeAlgebra();
Cv = Builder.CreateUIToFP(Cv, Ty);
Step = Builder.CreateFMul(Cv, Step);
if (isa<Instruction>(Step))
// Have to check, Step may be a constant
cast<Instruction>(Step)->setFastMathFlags(Flags);
Value *BOp = Builder.CreateBinOp(BinOp, Val, Step, "induction");
if (isa<Instruction>(BOp))
cast<Instruction>(BOp)->setFastMathFlags(Flags);
return BOp;
}
}
Value *InnerLoopVectorizer::getElementCount(Type* ElemTy, unsigned NumElts,
bool Scalable, Type* RetTy) {
if (!RetTy)
RetTy = Builder.getInt32Ty();
Value *V = UndefValue::get(VectorType::get(ElemTy, NumElts, Scalable));
return Builder.CreateElementCount(RetTy, V);
}
int LoopVectorizationLegality::isConsecutivePtr(Value *Ptr) {
assert(Ptr->getType()->isPointerTy() && "Unexpected non-ptr");
auto *SE = PSE.getSE();
// Make sure that the pointer does not point to structs.
if (Ptr->getType()->getPointerElementType()->isAggregateType())
return 0;
// If this value is a pointer induction variable, we know it is consecutive.
PHINode *Phi = dyn_cast_or_null<PHINode>(Ptr);
if (Phi && Inductions.count(Phi)) {
InductionDescriptor II = Inductions[Phi];
return II.getConsecutiveDirection();
}
GetElementPtrInst *Gep = getGEPInstruction(Ptr);
if (!Gep)
return 0;
unsigned NumOperands = Gep->getNumOperands();
Value *GpPtr = Gep->getPointerOperand();
// If this GEP value is a consecutive pointer induction variable and all of
// the indices are constant, then we know it is consecutive.
Phi = dyn_cast<PHINode>(GpPtr);
if (Phi && Inductions.count(Phi)) {
// Make sure that the pointer does not point to structs.
PointerType *GepPtrType = cast<PointerType>(GpPtr->getType());
if (GepPtrType->getElementType()->isAggregateType())
return 0;
// Make sure that all of the index operands are loop invariant.
for (unsigned i = 1; i < NumOperands; ++i)
if (!SE->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)), TheLoop))
return 0;
InductionDescriptor II = Inductions[Phi];
return II.getConsecutiveDirection();
}
unsigned InductionOperand = getGEPInductionOperand(Gep);
// Check that all of the gep indices are uniform except for our induction
// operand.
for (unsigned i = 0; i != NumOperands; ++i)
if (i != InductionOperand &&
!SE->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)), TheLoop))
return 0;
// We can emit wide load/stores only if the last non-zero index is the
// induction variable.
const SCEV *Last = nullptr;
if (!Strides.count(Gep))
Last = PSE.getSCEV(Gep->getOperand(InductionOperand));
else {
// Because of the multiplication by a stride we can have a s/zext cast.
// We are going to replace this stride by 1 so the cast is safe to ignore.
//
// %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
// %0 = trunc i64 %indvars.iv to i32
// %mul = mul i32 %0, %Stride1
// %idxprom = zext i32 %mul to i64 << Safe cast.
// %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom
//
Last = replaceSymbolicStrideSCEV(PSE, Strides,
Gep->getOperand(InductionOperand), Gep);
if (const SCEVCastExpr *C = dyn_cast<SCEVCastExpr>(Last))
Last =
(C->getSCEVType() == scSignExtend || C->getSCEVType() == scZeroExtend)
? C->getOperand()
: Last;
}
if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Last)) {
const SCEV *Step = AR->getStepRecurrence(*SE);
// The memory is consecutive because the last index is consecutive
// and all other indices are loop invariant.
if (Step->isOne())
return 1;
if (Step->isAllOnesValue())
return -1;
// Try and find a different constant stride
if (EnableNonConsecutiveStrideIndVars) {
if (const SCEVConstant *SCC = dyn_cast<SCEVConstant>(Step)) {
const ConstantInt *CI = SCC->getValue();
// TODO: Error checking vs. INT_MAX?
return (int)CI->getLimitedValue(INT_MAX);
}
}
}
return 0;
}
bool LoopVectorizationLegality::isUniform(Value *V) {
return LAI->isUniform(V);
}
InnerLoopVectorizer::VectorParts &
InnerLoopVectorizer::getVectorValue(Value *V) {
assert(V != Induction && "The new induction variable should not be used.");
assert(!V->getType()->isVectorTy() && "Can't widen a vector");
// If we have a stride that is replaced by one, do it here.
if (Legal->hasStride(V))
V = ConstantInt::get(V->getType(), 1);
// If we have this scalar in the map, return it.
if (WidenMap.has(V))
return WidenMap.get(V);
// If this scalar is unknown, assume that it is a constant or that it is
// loop invariant. Broadcast V and save the value for future uses.
Value *B = getBroadcastInstrs(V);
return WidenMap.splat(V, B);
}
Value *InnerLoopVectorizer::reverseVector(Value *Vec) {
assert(Vec->getType()->isVectorTy() && "Invalid type");
VectorType *Ty = cast<VectorType>(Vec->getType());
// i32 reverse_mask[n] = { n-1, n-2...1, 0 }
Value *NumEls = getElementCount(Ty->getElementType(), VF, Scalable);
Value *Start = Builder.CreateSub(NumEls, Builder.getInt32(1));
Value *Step = ConstantInt::get(Start->getType(), -1, true);
Value *Mask = Builder.CreateSeriesVector({VF,Scalable}, Start, Step);
return Builder.CreateShuffleVector(Vec, UndefValue::get(Ty), Mask, "reverse");
}
// Get a mask to interleave \p NumVec vectors into a wide vector.
// I.e. <0, VF, VF*2, ..., VF*(NumVec-1), 1, VF+1, VF*2+1, ...>
// E.g. For 2 interleaved vectors, if VF is 4, the mask is:
// <0, 4, 1, 5, 2, 6, 3, 7>
static Constant *getInterleavedMask(IRBuilder<> &Builder, unsigned VF,
unsigned NumVec) {
SmallVector<Constant *, 16> Mask;
for (unsigned i = 0; i < VF; i++)
for (unsigned j = 0; j < NumVec; j++)
Mask.push_back(Builder.getInt32(j * VF + i));
return ConstantVector::get(Mask);
}
// Get the strided mask starting from index \p Start.
// I.e. <Start, Start + Stride, ..., Start + Stride*(VF-1)>
static Constant *getStridedMask(IRBuilder<> &Builder, unsigned Start,
unsigned Stride, unsigned VF) {
SmallVector<Constant *, 16> Mask;
for (unsigned i = 0; i < VF; i++)
Mask.push_back(Builder.getInt32(Start + i * Stride));
return ConstantVector::get(Mask);
}
// Get a mask of two parts: The first part consists of sequential integers
// starting from 0, The second part consists of UNDEFs.
// I.e. <0, 1, 2, ..., NumInt - 1, undef, ..., undef>
static Constant *getSequentialMask(IRBuilder<> &Builder, unsigned NumInt,
unsigned NumUndef) {
SmallVector<Constant *, 16> Mask;
for (unsigned i = 0; i < NumInt; i++)
Mask.push_back(Builder.getInt32(i));
Constant *Undef = UndefValue::get(Builder.getInt32Ty());
for (unsigned i = 0; i < NumUndef; i++)
Mask.push_back(Undef);
return ConstantVector::get(Mask);
}
// Concatenate two vectors with the same element type. The 2nd vector should
// not have more elements than the 1st vector. If the 2nd vector has less
// elements, extend it with UNDEFs.
static Value *ConcatenateTwoVectors(IRBuilder<> &Builder, Value *V1,
Value *V2) {
VectorType *VecTy1 = dyn_cast<VectorType>(V1->getType());
VectorType *VecTy2 = dyn_cast<VectorType>(V2->getType());
assert(VecTy1 && VecTy2 &&
VecTy1->getScalarType() == VecTy2->getScalarType() &&
"Expect two vectors with the same element type");
unsigned NumElts1 = VecTy1->getNumElements();
unsigned NumElts2 = VecTy2->getNumElements();
assert(NumElts1 >= NumElts2 && "Unexpect the first vector has less elements");
if (NumElts1 > NumElts2) {
// Extend with UNDEFs.
Constant *ExtMask =
getSequentialMask(Builder, NumElts2, NumElts1 - NumElts2);
V2 = Builder.CreateShuffleVector(V2, UndefValue::get(VecTy2), ExtMask);
}
Constant *Mask = getSequentialMask(Builder, NumElts1 + NumElts2, 0);
return Builder.CreateShuffleVector(V1, V2, Mask);
}
// Concatenate vectors in the given list. All vectors have the same type.
static Value *ConcatenateVectors(IRBuilder<> &Builder,
ArrayRef<Value *> InputList) {
unsigned NumVec = InputList.size();
assert(NumVec > 1 && "Should be at least two vectors");
SmallVector<Value *, 8> ResList;
ResList.append(InputList.begin(), InputList.end());
do {
SmallVector<Value *, 8> TmpList;
for (unsigned i = 0; i < NumVec - 1; i += 2) {
Value *V0 = ResList[i], *V1 = ResList[i + 1];
assert((V0->getType() == V1->getType() || i == NumVec - 2) &&
"Only the last vector may have a different type");
TmpList.push_back(ConcatenateTwoVectors(Builder, V0, V1));
}
// Push the last vector if the total number of vectors is odd.
if (NumVec % 2 != 0)
TmpList.push_back(ResList[NumVec - 1]);
ResList = TmpList;
NumVec = ResList.size();
} while (NumVec > 1);
return ResList[0];
}
// Try to vectorize the interleave group that \p Instr belongs to.
//
// E.g. Translate following interleaved load group (factor = 3):
// for (i = 0; i < N; i+=3) {
// R = Pic[i]; // Member of index 0
// G = Pic[i+1]; // Member of index 1
// B = Pic[i+2]; // Member of index 2
// ... // do something to R, G, B
// }
// To:
// %wide.vec = load <12 x i32> ; Read 4 tuples of R,G,B
// %R.vec = shuffle %wide.vec, undef, <0, 3, 6, 9> ; R elements
// %G.vec = shuffle %wide.vec, undef, <1, 4, 7, 10> ; G elements
// %B.vec = shuffle %wide.vec, undef, <2, 5, 8, 11> ; B elements
//
// Or translate following interleaved store group (factor = 3):
// for (i = 0; i < N; i+=3) {
// ... do something to R, G, B
// Pic[i] = R; // Member of index 0
// Pic[i+1] = G; // Member of index 1
// Pic[i+2] = B; // Member of index 2
// }
// To:
// %R_G.vec = shuffle %R.vec, %G.vec, <0, 1, 2, ..., 7>
// %B_U.vec = shuffle %B.vec, undef, <0, 1, 2, 3, u, u, u, u>
// %interleaved.vec = shuffle %R_G.vec, %B_U.vec,
// <0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11> ; Interleave R,G,B elements
// store <12 x i32> %interleaved.vec ; Write 4 tuples of R,G,B
void InnerLoopVectorizer::vectorizeInterleaveGroup(Instruction *Instr) {
const InterleaveGroup *Group = Legal->getInterleavedAccessGroup(Instr);
assert(Group && "Fail to get an interleaved access group.");
// Skip if current instruction is not the insert position.
if (Instr != Group->getInsertPos())
return;
LoadInst *LI = dyn_cast<LoadInst>(Instr);
StoreInst *SI = dyn_cast<StoreInst>(Instr);
Value *Ptr = LI ? LI->getPointerOperand() : SI->getPointerOperand();
// Prepare for the vector type of the interleaved load/store.
Type *ScalarTy = LI ? LI->getType() : SI->getValueOperand()->getType();
unsigned InterleaveFactor = Group->getFactor();
Type *VecTy = VectorType::get(ScalarTy, InterleaveFactor * VF, Scalable);
Type *PtrTy = VecTy->getPointerTo(Ptr->getType()->getPointerAddressSpace());
// Prepare for the new pointers.
setDebugLocFromInst(Builder, Ptr);
VectorParts &PtrParts = getVectorValue(Ptr);
SmallVector<Value *, 2> NewPtrs;
unsigned Index = Group->getIndex(Instr);
for (unsigned Part = 0; Part < UF; Part++) {
// Extract the pointer for current instruction from the pointer vector. A
// reverse access uses the pointer in the last lane.
Value *NewPtr = Builder.CreateExtractElement(
PtrParts[Part],
Group->isReverse() ? Builder.getInt32(VF - 1) : Builder.getInt32(0));
// Notice current instruction could be any index. Need to adjust the address
// to the member of index 0.
//
// E.g. a = A[i+1]; // Member of index 1 (Current instruction)
// b = A[i]; // Member of index 0
// Current pointer is pointed to A[i+1], adjust it to A[i].
//
// E.g. A[i+1] = a; // Member of index 1
// A[i] = b; // Member of index 0
// A[i+2] = c; // Member of index 2 (Current instruction)
// Current pointer is pointed to A[i+2], adjust it to A[i].
NewPtr = Builder.CreateGEP(NewPtr, Builder.getInt32(-Index));
// Cast to the vector pointer type.
NewPtrs.push_back(Builder.CreateBitCast(NewPtr, PtrTy));
}
setDebugLocFromInst(Builder, Instr);
Value *UndefVec = UndefValue::get(VecTy);
// Vectorize the interleaved load group.
if (LI) {
for (unsigned Part = 0; Part < UF; Part++) {
Instruction *NewLoadInstr = Builder.CreateAlignedLoad(
NewPtrs[Part], Group->getAlignment(), "wide.vec");
for (unsigned i = 0; i < InterleaveFactor; i++) {
Instruction *Member = Group->getMember(i);
// Skip the gaps in the group.
if (!Member)
continue;
Constant *StrideMask = getStridedMask(Builder, i, InterleaveFactor, VF);
Value *StridedVec = Builder.CreateShuffleVector(
NewLoadInstr, UndefVec, StrideMask, "strided.vec");
// If this member has different type, cast the result type.
if (Member->getType() != ScalarTy) {
VectorType *OtherVTy = VectorType::get(Member->getType(), VF,
Scalable);
StridedVec = Builder.CreateBitOrPointerCast(StridedVec, OtherVTy);
}
VectorParts &Entry = WidenMap.get(Member);
Entry[Part] =
Group->isReverse() ? reverseVector(StridedVec) : StridedVec;
}
addMetadata(NewLoadInstr, Instr);
}
return;
}
// The sub vector type for current instruction.
VectorType *SubVT = VectorType::get(ScalarTy, VF, Scalable);
// Vectorize the interleaved store group.
for (unsigned Part = 0; Part < UF; Part++) {
// Collect the stored vector from each member.
SmallVector<Value *, 4> StoredVecs;
for (unsigned i = 0; i < InterleaveFactor; i++) {
// Interleaved store group doesn't allow a gap, so each index has a member
Instruction *Member = Group->getMember(i);
assert(Member && "Fail to get a member from an interleaved store group");
Value *StoredVec =
getVectorValue(dyn_cast<StoreInst>(Member)->getValueOperand())[Part];
if (Group->isReverse())
StoredVec = reverseVector(StoredVec);
// If this member has different type, cast it to an unified type.
if (StoredVec->getType() != SubVT)
StoredVec = Builder.CreateBitOrPointerCast(StoredVec, SubVT);
StoredVecs.push_back(StoredVec);
}
// Concatenate all vectors into a wide vector.
Value *WideVec = ConcatenateVectors(Builder, StoredVecs);
// Interleave the elements in the wide vector.
Constant *IMask = getInterleavedMask(Builder, VF, InterleaveFactor);
Value *IVec = Builder.CreateShuffleVector(WideVec, UndefVec, IMask,
"interleaved.vec");
Instruction *NewStoreInstr =
Builder.CreateAlignedStore(IVec, NewPtrs[Part], Group->getAlignment());
addMetadata(NewStoreInstr, Instr);
}
}
static bool storeToSameAddress(ScalarEvolution *SE, StoreInst *A, StoreInst *B) {
// Keep aliasing simple by rejecting all but identical stores.
if (A->getType() != B->getType())
return false;
// Compare store
if (A == B)
return true;
// Otherwise Compare pointers
Value *APtr = A->getPointerOperand();
Value *BPtr = B->getPointerOperand();
if (A == B)
return true;
// Otherwise compare address SCEVs
if (SE->getSCEV(APtr) == SE->getSCEV(BPtr))
return true;
return false;
}
void InnerLoopVectorizer::vectorizeMemsetInstruction(MemSetInst *MSI) {
const auto Length = MSI->getLength();
const auto IsVolatile = MSI->isVolatile();
// Clamp Alignment to yield an acceptable vector element type.
const auto Alignment = std::min(MSI->getAlignmentCst()->getZExtValue(),
(uint64_t) 8);
const auto Val = MSI->getValue();
const auto Dest = MSI->getRawDest();
auto CL = dyn_cast<ConstantInt>(Length);
assert(CL && "Not a constant value.");
assert((CL->getZExtValue() % Alignment == 0)
&& "Not a valid number of writes.");
assert(((CL->getZExtValue() / Alignment) <= VectorizerMemSetThreshold)
&& "Not a valid number of elements.");
assert(!IsVolatile && "Cannot transform a volatile memset.");
assert(VectorizeMemset && "Should not vectorize memset.");
assert(isScalable() && "Require WA.");
VectorParts &Ptrs = getVectorValue(Dest);
VectorParts &Vals = getVectorValue(Val);
for (unsigned Part = 0; Part < UF; ++Part) {
auto *Ctx = &MSI->getParent()->getParent()->getContext();
assert(Vals[Part]->getType()->getScalarType()->getScalarSizeInBits() == 8
&& "Invalid pointer");
Type *WideScalarTy = IntegerType::get(*Ctx, 8 * Alignment);
VectorType::ElementCount EC(VF * Alignment, Scalable);
Value *VecVal = Builder.CreateVectorSplat(EC, Val);
auto WideVecTy = VectorType::get(WideScalarTy, VF, Scalable);
VecVal = Builder.CreateBitCast(VecVal, WideVecTy);
// Generate the actual memset replacement.
auto AddrSpace = Ptrs[Part]->getType()->getPointerAddressSpace();
auto WideVecPtrTy = VectorType::get(WideScalarTy->getPointerTo(AddrSpace),
VF, Scalable);
Value *P = Predicate[Part];
for (unsigned i = 0; i < CL->getZExtValue(); i+=Alignment) {
auto Ptr = Builder.CreateGEP(Ptrs[Part], Builder.getInt32(i));
Ptr = Builder.CreateBitCast(Ptr, WideVecPtrTy);
auto *NewMemset = Builder.CreateMaskedScatter(VecVal, Ptr, Alignment, P);
propagateMetadata(NewMemset, MSI);
}
}
}
void InnerLoopVectorizer::vectorizeMemoryInstruction(Instruction *Instr) {
// Attempt to issue a wide load.
LoadInst *LI = dyn_cast<LoadInst>(Instr);
StoreInst *SI = dyn_cast<StoreInst>(Instr);
assert((LI || SI) && "Invalid Load/Store instruction");
// Don't create a memory instruction for an intermediate store of a
// reduction variable, because this will be one to a uniform address.
if (SI) {
for (auto &Reduction : *Legal->getReductionVars()) {
RecurrenceDescriptor DS = Reduction.second;
if (DS.IntermediateStore &&
storeToSameAddress(PSE.getSE(), SI, DS.IntermediateStore))
return;
}
}
// Try to vectorize the interleave group if this access is interleaved.
if (Legal->isAccessInterleaved(Instr))
return vectorizeInterleaveGroup(Instr);
Type *ScalarDataTy = LI ? LI->getType() : SI->getValueOperand()->getType();
Type *DataTy = VectorType::get(ScalarDataTy, VF, Scalable);
Value *Ptr = LI ? LI->getPointerOperand() : SI->getPointerOperand();
unsigned Alignment = LI ? LI->getAlignment() : SI->getAlignment();
// An alignment of 0 means target abi alignment. We need to use the scalar's
// target abi alignment in such a case.
const DataLayout &DL = Instr->getModule()->getDataLayout();
if (!Alignment)
Alignment = DL.getABITypeAlignment(ScalarDataTy);
unsigned AddressSpace = Ptr->getType()->getPointerAddressSpace();
unsigned ScalarAllocatedSize = DL.getTypeAllocSize(ScalarDataTy);
unsigned VectorElementSize = DL.getTypeStoreSize(DataTy) / VF;
if (SI && Legal->blockNeedsPredication(SI->getParent()) &&
!Legal->isMaskRequired(SI) && !UsePredication)
return scalarizeInstruction(Instr, true);
if (ScalarAllocatedSize != VectorElementSize)
return scalarizeInstruction(Instr);
Constant *Zero = Builder.getInt32(0);
VectorParts &Entry = WidenMap.get(Instr);
// If the pointer is loop invariant scalarize the load.
if (LI && Legal->isUniform(Ptr)) {
// ... unless we're vectorizing for a scalable architecture.
if (isScalable()) {
// The pointer may be uniform from SCEV perspective,
// but may not be hoisted out for other reasons.
auto *PtrI = dyn_cast<Instruction>(Ptr);
if (PtrI && OrigLoop->contains(PtrI)) {
Ptr = Builder.CreateExtractElement(getVectorValue(Ptr)[0],
Builder.getInt32(0));
}
// Generate a scalar load...
Instruction *NewLI = Builder.CreateLoad(Ptr);
propagateMetadata(NewLI, LI);
// ... and splat it.
for (unsigned Part = 0; Part < UF; ++Part) {
Entry[Part] =
Builder.CreateVectorSplat({VF, Scalable}, NewLI, "uniform_load");
}
} else
scalarizeInstruction(Instr);
return;
}
// If the pointer is non-consecutive and gather/scatter is not supported
// scalarize the instruction.
int Stride = Legal->isConsecutivePtr(Ptr);
bool Reverse = Stride < 0;
bool HasConsecutiveStride = (std::abs(Stride) == 1);
bool CreateGatherScatter =
!HasConsecutiveStride &&
((LI && Legal->isLegalMaskedGather(ScalarDataTy)) ||
(SI && Legal->isLegalMaskedScatter(ScalarDataTy)));
if (!HasConsecutiveStride && !CreateGatherScatter)
return scalarizeInstruction(Instr);
VectorParts VectorGep;
GetElementPtrInst *Gep = getGEPInstruction(Ptr);
if (HasConsecutiveStride) {
if (Gep && Legal->isInductionVariable(Gep->getPointerOperand())) {
setDebugLocFromInst(Builder, Gep);
Value *PtrOperand = Gep->getPointerOperand();
Value *FirstBasePtr = getVectorValue(PtrOperand)[0];
FirstBasePtr = Builder.CreateExtractElement(FirstBasePtr, Zero);
// Create the new GEP with the new induction variable.
GetElementPtrInst *Gep2 = cast<GetElementPtrInst>(Gep->clone());
Gep2->setOperand(0, FirstBasePtr);
Gep2->setName("gep.indvar.base");
Ptr = Builder.Insert(Gep2);
} else if (Gep) {
setDebugLocFromInst(Builder, Gep);
assert(PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),
OrigLoop) &&
"Base ptr must be invariant");
// The last index does not have to be the induction. It can be
// consecutive and be a function of the index. For example A[I+1];
unsigned NumOperands = Gep->getNumOperands();
unsigned InductionOperand = getGEPInductionOperand(Gep);
// Create the new GEP with the new induction variable.
GetElementPtrInst *Gep2 = cast<GetElementPtrInst>(Gep->clone());
for (unsigned i = 0; i < NumOperands; ++i) {
Value *GepOperand = Gep->getOperand(i);
Instruction *GepOperandInst = dyn_cast<Instruction>(GepOperand);
// Update last index or loop invariant instruction anchored in loop.
if (i == InductionOperand ||
(GepOperandInst && OrigLoop->contains(GepOperandInst))) {
assert((i == InductionOperand ||
PSE.getSE()->isLoopInvariant(PSE.getSCEV(GepOperandInst),
OrigLoop)) &&
"Must be last index or loop invariant");
VectorParts &GEPParts = getVectorValue(GepOperand);
Value *Index = GEPParts[0];
Index = Builder.CreateExtractElement(Index, Zero);
Gep2->setOperand(i, Index);
Gep2->setName("gep.indvar.idx");
}
}
Ptr = Builder.Insert(Gep2);
} else { // No GEP
// Use the induction element ptr.
assert(isa<PHINode>(Ptr) && "Invalid induction ptr");
setDebugLocFromInst(Builder, Ptr);
VectorParts &PtrVal = getVectorValue(Ptr);
Ptr = Builder.CreateExtractElement(PtrVal[0], Zero);
}
} else {
// At this point we should vector version of GEP for Gather or Scatter
assert(CreateGatherScatter && "The instruction should be scalarized");
// For scalable vectorization, vectorizeGEPInstruction has already
// handled this. Only useful for fixed-length.
// TODO: Unify this version with the scalable code once we can discuss with
// the community.
if (Gep && !isScalable()) {
SmallVector<VectorParts, 4> OpsV;
// Vectorizing GEP, across UF parts, we want to keep each loop-invariant
// base or index of GEP scalar
for (Value *Op : Gep->operands()) {
if (PSE.getSE()->isLoopInvariant(PSE.getSCEV(Op), OrigLoop))
OpsV.push_back(VectorParts(UF, Op));
else
OpsV.push_back(getVectorValue(Op));
}
for (unsigned Part = 0; Part < UF; ++Part) {
SmallVector<Value *, 4> Ops;
Value *GEPBasePtr = OpsV[0][Part];
for (unsigned i = 1; i < Gep->getNumOperands(); i++)
Ops.push_back(OpsV[i][Part]);
Value *NewGep =
Builder.CreateGEP(nullptr, GEPBasePtr, Ops, "VectorGep");
assert(NewGep->getType()->isVectorTy() && "Expected vector GEP");
NewGep =
Builder.CreateBitCast(NewGep, VectorType::get(Ptr->getType(),
{VF, Scalable}));
VectorGep.push_back(NewGep);
}
} else
VectorGep = getVectorValue(Ptr);
}
Type *DataPtrTy = DataTy->getPointerTo(AddressSpace);
VectorParts Mask = createBlockInMask(Instr->getParent());
VectorParts PredStoreMask;
if (SI && Legal->blockNeedsPredication(SI->getParent()) &&
!Legal->isMaskRequired(SI)) {
assert(UsePredication && "Cannot predicate store without predication.");
assert(SI->getParent()->getSinglePredecessor() &&
"Only support single predecessor blocks.");
PredStoreMask = createEdgeMask(SI->getParent()->getSinglePredecessor(),
SI->getParent());
}
// Handle Stores:
if (SI) {
assert(!Legal->isUniform(SI->getPointerOperand()) &&
"We do not allow storing to uniform addresses");
setDebugLocFromInst(Builder, SI);
// We don't want to update the value in the map as it might be used in
// another expression. So don't use a reference type for "StoredVal".
VectorParts StoredVal = getVectorValue(SI->getValueOperand());
for (unsigned Part = 0; Part < UF; ++Part) {
Instruction *NewSI = nullptr;
if (CreateGatherScatter) {
Value *P = Predicate[Part];
if (Legal->isMaskRequired(SI))
P = Builder.CreateAnd(P, Mask[Part]);
NewSI = Builder.CreateMaskedScatter(StoredVal[Part], VectorGep[Part],
Alignment, P);
} else {
// Calculate the pointer for the specific unroll-part.
Value *VecPtr;
Value *MaskPart = Mask[Part];
Value *Data = StoredVal[Part];
if (UsePredication)
MaskPart = Builder.CreateAnd(MaskPart, Predicate[Part]);
if (Reverse) {
// If we store to reverse consecutive memory locations, then we need
// to reverse the order of elements in the stored value.
Data = reverseVector(Data);
// If the address is consecutive but reversed, then the
// wide store needs to start at the last vector element.
VecPtr = Builder.CreateGEP(nullptr, Ptr, Builder.getInt32(1));
VecPtr = Builder.CreateBitCast(VecPtr, DataPtrTy);
VecPtr = Builder.CreateGEP(nullptr, VecPtr, Builder.getInt32(-Part-1));
MaskPart = reverseVector(MaskPart);
} else {
VecPtr = Builder.CreateBitCast(Ptr, DataPtrTy);
VecPtr = Builder.CreateGEP(nullptr, VecPtr, Builder.getInt32(Part));
}
if (Legal->isMaskRequired(SI))
NewSI = Builder.CreateMaskedStore(Data, VecPtr, Alignment, MaskPart);
else if (UsePredication) {
Value* P = Predicate[Part];
if (Legal->blockNeedsPredication(SI->getParent()))
P = Builder.CreateAnd(P, PredStoreMask[Part]);
if (Reverse)
P = reverseVector(P);
NewSI = Builder.CreateMaskedStore(Data, VecPtr, Alignment, P);
} else
NewSI = Builder.CreateAlignedStore(Data, VecPtr, Alignment);
}
addMetadata(NewSI, SI);
}
return;
}
// Handle loads.
assert(LI && "Must have a load instruction");
setDebugLocFromInst(Builder, LI);
for (unsigned Part = 0; Part < UF; ++Part) {
Instruction *NewLI;
if (CreateGatherScatter) {
Value *P = Predicate[Part];
if (Legal->isMaskRequired(LI))
P = Builder.CreateAnd(P, Mask[Part]);
NewLI = Builder.CreateMaskedGather(VectorGep[Part], Alignment,
P, 0, "wide.masked.gather");
Entry[Part] = NewLI;
} else {
// Calculate the pointer for the specific unroll-part.
Value *VecPtr;
Value *MaskPart = Mask[Part];
if (UsePredication)
MaskPart = Builder.CreateAnd(MaskPart, Predicate[Part]);
if (Reverse) {
// If the address is consecutive but reversed, then the
// wide load needs to start at the last vector element.
VecPtr = Builder.CreateGEP(nullptr, Ptr, Builder.getInt32(1));
VecPtr = Builder.CreateBitCast(VecPtr, DataPtrTy);
VecPtr = Builder.CreateGEP(nullptr, VecPtr, Builder.getInt32(-Part-1));
MaskPart = reverseVector(MaskPart);
} else {
VecPtr = Builder.CreateBitCast(Ptr, DataPtrTy);
VecPtr = Builder.CreateGEP(nullptr, VecPtr, Builder.getInt32(Part));
}
if (Legal->isMaskRequired(LI))
NewLI = Builder.CreateMaskedLoad(VecPtr, Alignment, MaskPart,
UndefValue::get(DataTy),
"wide.masked.load");
else if (UsePredication) {
Value* P = Reverse ? reverseVector(Predicate[Part]) : Predicate[Part];
NewLI = Builder.CreateMaskedLoad(VecPtr, Alignment, P,
UndefValue::get(DataTy),
"wide.masked.load");
} else
NewLI = Builder.CreateAlignedLoad(VecPtr, Alignment, "wide.load");
Entry[Part] = Reverse ? reverseVector(NewLI) : NewLI;
}
addMetadata(NewLI, LI);
}
}
/// Depending on the access pattern, either of three things happen with
/// the GetElementPtr instruction:
/// - GEP is loop invariant:
/// Nothing
/// - GEP is affine function of loop iteration counter:
/// GEP is replaced by a seriesvector(%ptr, %stride)
/// - GEP is not affine:
/// - GEP pointer is a vectorized GEP instruction::
/// GEP is replaced by a vector of pointers using arithmetic
void InnerLoopVectorizer::vectorizeGEPInstruction(Instruction *Instr) {
GetElementPtrInst *Gep = cast<GetElementPtrInst>(Instr);
if (!isScalable()) {
scalarizeInstruction(Instr);
return;
}
auto *SE = PSE.getSE();
// Handle all non loop invariant forms that are not affine, so that
// when used as address it can be transformed into a gather load/store,
// or when used as pointer arithmetic, it is just vectorized into
// arithmetic instructions.
auto *SAR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(Gep));
if (!SAR || !SAR->isAffine()) {
vectorizeArithmeticGEP(Gep);
return;
}
// Create SCEV expander for Start- and StepValue
const DataLayout &DL = Instr->getModule()->getDataLayout();
SCEVExpander Expander(*SE, DL, "seriesgep");
// Expand step and start value (the latter in preheader)
const SCEV *StepRec = SAR->getStepRecurrence(*SE);
// If the step can't be divided by the type size of the GEP (for example if
// the type structure is { gep = { i64, i64 }, i64 }, then also use the
// pointer arithmetic vectorization.
if (auto *StepC = dyn_cast<SCEVConstant>(StepRec)) {
if (StepC->getAPInt().getZExtValue() %
DL.getTypeAllocSize(Gep->getType()->getPointerElementType())) {
vectorizeArithmeticGEP(Gep);
return;
}
}
Value *StepValue = Expander.expandCodeFor(StepRec, StepRec->getType(),
&*Builder.GetInsertPoint());
// Try to find a smaller type for StepValue
const SCEV *BETC = SE->getMaxBackedgeTakenCount(OrigLoop);
if (auto * MaxIters = dyn_cast<SCEVConstant>(BETC)) {
if (auto * CI = dyn_cast<ConstantInt>(StepValue)) {
// RequiredBits = active_bits(max_iterations * step_value)
APInt MaxItersV = MaxIters->getValue()->getValue();
if (CI->isNegative())
MaxItersV = MaxItersV.sextOrSelf(CI->getValue().getBitWidth());
else
MaxItersV = MaxItersV.zextOrSelf(CI->getValue().getBitWidth());
APInt MaxVal = MaxItersV * CI->getValue();
// Try to reduce this type from i64 to something smaller
unsigned RequiredBits = MaxVal.getActiveBits();
unsigned StepBits = StepValue->getType()->getIntegerBitWidth();
while (RequiredBits <= StepBits && StepBits >= 32)
StepBits = StepBits >> 1;
// Truncate the step value
Type *NewStepType = IntegerType::get(
Instr->getParent()->getContext(), StepBits << 1);
StepValue = Builder.CreateTrunc(StepValue, NewStepType);
}
}
const SCEV *StartRec = SAR->getStart();
Value *StartValue = Expander.expandCodeFor(
StartRec, Gep->getType(), LoopVectorPreHeader->getTerminator());
// Normalize Start offset for first iteration in case the
// Induction variable does not start at 0.
IRBuilder<>::InsertPoint IP = Builder.saveIP();
Builder.SetInsertPoint(&*LoopVectorPreHeader->getTerminator());
Value *Base = Gep->getPointerOperand();
Value *Tmp2 = Builder.CreateBitCast(StartValue,
Builder.getInt8PtrTy(Base->getType()->getPointerAddressSpace()));
// We can zero extend the incoming value, because Induction is
// the unsigned iteration counter.
Value *Tmp = Induction->getIncomingValueForBlock(LoopVectorPreHeader);
Tmp = Builder.CreateZExtOrTrunc(Tmp, StepValue->getType());
Tmp = Builder.CreateMul(StepValue, Tmp);
Tmp = Builder.CreateSub(ConstantInt::get(StepValue->getType(), 0), Tmp);
Tmp = Builder.CreateGEP(Tmp2, Tmp);
StartValue = Builder.CreateBitCast(Tmp, StartValue->getType());
Builder.restoreIP(IP);
// Normalize to be in #elements, not bytes
Type *ElemTy = Instr->getType()->getPointerElementType();
Tmp = ConstantInt::get(StepValue->getType(), DL.getTypeAllocSize(ElemTy));
StepValue = Builder.CreateSDiv(StepValue, Tmp);
// Get the dynamic VL
Value *NumEls = getElementCount(Instr->getType(), VF, Scalable);
NumEls = Builder.CreateZExtOrTrunc(NumEls, StepValue->getType());
// Create the series vector
VectorParts &Entry = WidenMap.get(Instr);
// Induction is always the widest induction type in the loop,
// but if that is not enough for evaluating the step, zero extend is
// fine because Induction is the iteration counter, always unsigned.
Value *IterOffset = Builder.CreateZExtOrTrunc(Induction, StepValue->getType());
IterOffset = Builder.CreateMul(IterOffset, StepValue);
for (unsigned Part = 0; Part < UF; ++Part) {
// Tmp = part * stride * VL
Value *UnrollOffset = ConstantInt::get(NumEls->getType(), Part);
UnrollOffset = Builder.CreateMul(StepValue, UnrollOffset);
UnrollOffset = Builder.CreateMul(NumEls, UnrollOffset);
// Adjust offset for unrolled iteration
Value *Offset = Builder.CreateAdd(IterOffset, UnrollOffset);
Offset = Builder.CreateSeriesVector({VF,Scalable}, Offset, StepValue);
// Address = getelementptr %scalarbase, seriesvector(0, step)
Entry[Part] = Builder.CreateGEP(StartValue, Offset);
}
addMetadata(Entry, Instr);
}
void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr,
bool IfPredicateStore) {
assert(!Instr->getType()->isAggregateType() && "Can't handle vectors");
assert(!isScalable() &&
"Cannot scalarize instruction with scalable vectorization");
// Holds vector parameters or scalars, in case of uniform vals.
SmallVector<VectorParts, 4> Params;
setDebugLocFromInst(Builder, Instr);
// Find all of the vectorized parameters.
for (unsigned op = 0, e = Instr->getNumOperands(); op != e; ++op) {
Value *SrcOp = Instr->getOperand(op);
// If we are accessing the old induction variable, use the new one.
if (SrcOp == OldInduction) {
Params.push_back(getVectorValue(SrcOp));
continue;
}
// Try using previously calculated values.
Instruction *SrcInst = dyn_cast<Instruction>(SrcOp);
// If the src is an instruction that appeared earlier in the basic block,
// then it should already be vectorized.
if (SrcInst && OrigLoop->contains(SrcInst)) {
assert(WidenMap.has(SrcInst) && "Source operand is unavailable");
// The parameter is a vector value from earlier.
Params.push_back(WidenMap.get(SrcInst));
} else {
// The parameter is a scalar from outside the loop. Maybe even a constant.
VectorParts Scalars;
Scalars.append(UF, SrcOp);
Params.push_back(Scalars);
}
}
assert(Params.size() == Instr->getNumOperands() &&
"Invalid number of operands");
// Does this instruction return a value ?
bool IsVoidRetTy = Instr->getType()->isVoidTy();
Value *UndefVec =
IsVoidRetTy ? nullptr
: UndefValue::get(VectorType::get(Instr->getType(), VF));
// Create a new entry in the WidenMap and initialize it to Undef or Null.
VectorParts &VecResults = WidenMap.splat(Instr, UndefVec);
VectorParts Cond;
if (IfPredicateStore) {
assert(Instr->getParent()->getSinglePredecessor() &&
"Only support single predecessor blocks");
Cond = createEdgeMask(Instr->getParent()->getSinglePredecessor(),
Instr->getParent());
}
// For each vector unroll 'part':
for (unsigned Part = 0; Part < UF; ++Part) {
// For each scalar that we create:
for (unsigned Width = 0; Width < VF; ++Width) {
// Start if-block.
Value *Cmp = nullptr;
if (IfPredicateStore) {
Cmp = Builder.CreateExtractElement(Cond[Part], Builder.getInt32(Width));
Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Cmp,
ConstantInt::get(Cmp->getType(), 1));
}
Instruction *Cloned = Instr->clone();
if (!IsVoidRetTy)
Cloned->setName(Instr->getName() + ".cloned");
// Replace the operands of the cloned instructions with extracted scalars.
for (unsigned op = 0, e = Instr->getNumOperands(); op != e; ++op) {
Value *Op = Params[op][Part];
// Param is a vector. Need to extract the right lane.
if (Op->getType()->isVectorTy())
Op = Builder.CreateExtractElement(Op, Builder.getInt32(Width));
Cloned->setOperand(op, Op);
}
addNewMetadata(Cloned, Instr);
// Place the cloned scalar in the new loop.
Builder.Insert(Cloned);
// If we just cloned a new assumption, add it the assumption cache.
if (auto *II = dyn_cast<IntrinsicInst>(Cloned))
if (II->getIntrinsicID() == Intrinsic::assume)
AC->registerAssumption(II);
// If the original scalar returns a value we need to place it in a vector
// so that future users will be able to use it.
if (!IsVoidRetTy)
VecResults[Part] = Builder.CreateInsertElement(VecResults[Part], Cloned,
Builder.getInt32(Width));
// End if-block.
if (IfPredicateStore)
PredicatedStores.push_back(
std::make_pair(cast<StoreInst>(Cloned), Cmp));
}
}
}
static Instruction *getFirstInst(Instruction *FirstInst, Value *V,
Instruction *Loc) {
if (FirstInst)
return FirstInst;
if (Instruction *I = dyn_cast<Instruction>(V))
return I->getParent() == Loc->getParent() ? I : nullptr;
return nullptr;
}
std::pair<Instruction *, Instruction *>
InnerLoopVectorizer::addStrideCheck(Instruction *Loc) {
Instruction *tnullptr = nullptr;
if (!Legal->mustCheckStrides())
return std::pair<Instruction *, Instruction *>(tnullptr, tnullptr);
IRBuilder<> ChkBuilder(Loc);
// Emit checks.
Value *Check = nullptr;
Instruction *FirstInst = nullptr;
for (SmallPtrSet<Value *, 8>::iterator SI = Legal->strides_begin(),
SE = Legal->strides_end();
SI != SE; ++SI) {
Value *Ptr = stripIntegerCast(*SI);
Value *C = ChkBuilder.CreateICmpNE(Ptr, ConstantInt::get(Ptr->getType(), 1),
"stride.chk");
// Store the first instruction we create.
FirstInst = getFirstInst(FirstInst, C, Loc);
if (Check)
Check = ChkBuilder.CreateOr(Check, C);
else
Check = C;
}
// We have to do this trickery because the IRBuilder might fold the check to a
// constant expression in which case there is no Instruction anchored in a
// the block.
LLVMContext &Ctx = Loc->getContext();
Instruction *TheCheck =
BinaryOperator::CreateAnd(Check, ConstantInt::getTrue(Ctx));
ChkBuilder.Insert(TheCheck, "stride.not.one");
FirstInst = getFirstInst(FirstInst, TheCheck, Loc);
return std::make_pair(FirstInst, TheCheck);
}
PHINode *InnerLoopVectorizer::createInductionVariable(Loop *L, Value *Start,
Value *End, Value *Step,
Instruction *DL) {
BasicBlock *Header = L->getHeader();
BasicBlock *Latch = L->getLoopLatch();
// As we're just creating this loop, it's possible no latch exists
// yet. If so, use the header as this will be a single block loop.
if (!Latch)
Latch = Header;
IRBuilder<> Builder(&*Header->getFirstInsertionPt());
setDebugLocFromInst(Builder, getDebugLocFromInstOrOperands(OldInduction));
auto *PredTy = VectorType::get(Builder.getInt1Ty(), VF, Scalable);
auto *AllActive = ConstantInt::getTrue(PredTy);
auto *Induction = Builder.CreatePHI(Start->getType(), 2, "index");
for (unsigned i = 0; i < UF; ++i)
Predicate.push_back(Builder.CreatePHI(PredTy, 2, "predicate"));
Builder.SetInsertPoint(Latch->getTerminator());
// Create i+1 and fill the PHINode.
Value *Next = Builder.CreateAdd(Induction, Step, "index.next");
Induction->addIncoming(Start, L->getLoopPreheader());
Induction->addIncoming(Next, Latch);
// Even though all lanes are active some code paths require a predicate.
for (unsigned i = 0; i < UF; ++i) {
Predicate[i]->addIncoming(AllActive, L->getLoopPreheader());
Predicate[i]->addIncoming(AllActive, Latch);
}
// Create the compare.
Value *ICmp = Builder.CreateICmpEQ(Next, End);
Builder.CreateCondBr(ICmp, L->getExitBlock(), Header);
// Now we have two terminators. Remove the old one from the block.
Latch->getTerminator()->eraseFromParent();
return Induction;
}
Value *InnerLoopVectorizer::getOrCreateTripCount(Loop *L) {
if (TripCount)
return TripCount;
IRBuilder<> Builder(L->getLoopPreheader()->getTerminator());
// Find the loop boundaries.
ScalarEvolution *SE = PSE.getSE();
const SCEV *BackedgeTakenCount = PSE.getBackedgeTakenCount();
assert(BackedgeTakenCount != SE->getCouldNotCompute() &&
"Invalid loop count");
Type *IdxTy = Legal->getWidestInductionType();
// The exit count might have the type of i64 while the phi is i32. This can
// happen if we have an induction variable that is sign extended before the
// compare. The only way that we get a backedge taken count is that the
// induction variable was signed and as such will not overflow. In such a case
// truncation is legal.
if (BackedgeTakenCount->getType()->getPrimitiveSizeInBits() >
IdxTy->getPrimitiveSizeInBits())
BackedgeTakenCount = SE->getTruncateOrNoop(BackedgeTakenCount, IdxTy);
BackedgeTakenCount = SE->getNoopOrZeroExtend(BackedgeTakenCount, IdxTy);
// Get the total trip count from the count by adding 1.
const SCEV *ExitCount = SE->getAddExpr(
BackedgeTakenCount, SE->getOne(BackedgeTakenCount->getType()));
const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
// Expand the trip count and place the new instructions in the preheader.
// Notice that the pre-header does not change, only the loop body.
SCEVExpander Exp(*SE, DL, "induction");
// Count holds the overall loop count (N).
TripCount = Exp.expandCodeFor(ExitCount, ExitCount->getType(),
L->getLoopPreheader()->getTerminator());
if (TripCount->getType()->isPointerTy())
TripCount =
CastInst::CreatePointerCast(TripCount, IdxTy, "exitcount.ptrcnt.to.int",
L->getLoopPreheader()->getTerminator());
return TripCount;
}
Value *InnerLoopVectorizer::getOrCreateVectorTripCount(Loop *L) {
if (VectorTripCount)
return VectorTripCount;
Value *TC = getOrCreateTripCount(L);
if (UsePredication) {
// All iterations are done by the vector body so VectorTripCount==TripCount.
VectorTripCount = TC;
return VectorTripCount;
}
IRBuilder<> Builder(L->getLoopPreheader()->getTerminator());
// Now we need to generate the expression for N - (N % VF), which is
// the part that the vectorized body will execute.
// The loop step is equal to the vectorization factor (num of SIMD elements)
// times the unroll factor (num of SIMD instructions).
Value *R = Builder.CreateURem(TC, InductionStep, "n.mod.vf");
// If there is a non-reversed interleaved group that may speculatively access
// memory out-of-bounds, we need to ensure that there will be at least one
// iteration of the scalar epilogue loop. Thus, if the step evenly divides
// the trip count, we set the remainder to be equal to the step. If the step
// does not evenly divide the trip count, no adjustment is necessary since
// there will already be scalar iterations. Note that the minimum iterations
// check ensures that N >= Step.
if (VF > 1 && !Scalable && Legal->requiresScalarEpilogue()) {
auto *IsZero = Builder.CreateICmpEQ(R, ConstantInt::get(R->getType(), 0));
R = Builder.CreateSelect(IsZero, InductionStep, R);
}
VectorTripCount = Builder.CreateSub(TC, R, "n.vec");
return VectorTripCount;
}
Value *InnerLoopVectorizer::getOrCreateInductionStep(Loop *L) {
if (InductionStep)
return InductionStep;
IRBuilder<> Builder(L->getLoopPreheader()->getTerminator());
Value *TC = getOrCreateTripCount(L);
Type *IdxTy = TC->getType();
auto *TV = UndefValue::get(VectorType::get(IdxTy, VF, Scalable));
auto *ActualVF = Builder.CreateElementCount(IdxTy, TV);
InductionStep = Builder.CreateMul(ActualVF, ConstantInt::get(IdxTy, UF));
return InductionStep;
}
void InnerLoopVectorizer::emitMinimumIterationCountCheck(Loop *L,
Value *MinCount,
BasicBlock *Bypass) {
Value *Count = getOrCreateTripCount(L);
BasicBlock *BB = L->getLoopPreheader();
IRBuilder<> Builder(BB->getTerminator());
// Generate code to check that the loop's trip count that we computed by
// adding one to the backedge-taken count will not overflow.
Value *CheckMinIters = Builder.CreateICmpULT(Count, MinCount,
"min.iters.check");
BasicBlock *NewBB =
BB->splitBasicBlock(BB->getTerminator(), "min.iters.checked");
// Update dominator tree immediately if the generated block is a
// LoopBypassBlock because SCEV expansions to generate loop bypass
// checks may query it before the current function is finished.
DT->addNewBlock(NewBB, BB);
if (L->getParentLoop())
L->getParentLoop()->addBasicBlockToLoop(NewBB, *LI);
ReplaceInstWithInst(BB->getTerminator(),
BranchInst::Create(Bypass, NewBB, CheckMinIters));
LoopBypassBlocks.push_back(BB);
}
void InnerLoopVectorizer::emitVectorLoopEnteredCheck(Loop *L,
BasicBlock *Bypass) {
Value *TC = getOrCreateVectorTripCount(L);
BasicBlock *BB = L->getLoopPreheader();
IRBuilder<> Builder(BB->getTerminator());
// Now, compare the new count to zero. If it is zero skip the vector loop and
// jump to the scalar loop.
Value *Cmp = Builder.CreateICmpEQ(TC, Constant::getNullValue(TC->getType()),
"cmp.zero");
// Generate code to check that the loop's trip count that we computed by
// adding one to the backedge-taken count will not overflow.
BasicBlock *NewBB = BB->splitBasicBlock(BB->getTerminator(), "vector.ph");
// Update dominator tree immediately if the generated block is a
// LoopBypassBlock because SCEV expansions to generate loop bypass
// checks may query it before the current function is finished.
DT->addNewBlock(NewBB, BB);
if (L->getParentLoop())
L->getParentLoop()->addBasicBlockToLoop(NewBB, *LI);
ReplaceInstWithInst(BB->getTerminator(),
BranchInst::Create(Bypass, NewBB, Cmp));
LoopBypassBlocks.push_back(BB);
}
void InnerLoopVectorizer::emitSCEVChecks(Loop *L, BasicBlock *Bypass) {
BasicBlock *BB = L->getLoopPreheader();
// Generate the code to check that the SCEV assumptions that we made.
// We want the new basic block to start at the first instruction in a
// sequence of instructions that form a check.
SCEVExpander Exp(*PSE.getSE(), Bypass->getModule()->getDataLayout(),
"scev.check");
Value *SCEVCheck =
Exp.expandCodeForPredicate(&PSE.getUnionPredicate(), BB->getTerminator());
if (auto *C = dyn_cast<ConstantInt>(SCEVCheck))
if (C->isZero())
return;
// Create a new block containing the stride check.
BB->setName("vector.scevcheck");
auto *NewBB = BB->splitBasicBlock(BB->getTerminator(), "vector.ph");
// Update dominator tree immediately if the generated block is a
// LoopBypassBlock because SCEV expansions to generate loop bypass
// checks may query it before the current function is finished.
DT->addNewBlock(NewBB, BB);
if (L->getParentLoop())
L->getParentLoop()->addBasicBlockToLoop(NewBB, *LI);
ReplaceInstWithInst(BB->getTerminator(),
BranchInst::Create(Bypass, NewBB, SCEVCheck));
LoopBypassBlocks.push_back(BB);
AddedSafetyChecks = true;
}
void InnerLoopVectorizer::emitMemRuntimeChecks(Loop *L, BasicBlock *Bypass) {
BasicBlock *BB = L->getLoopPreheader();
// Generate the code that checks in runtime if arrays overlap. We put the
// checks into a separate block to make the more common case of few elements
// faster.
Instruction *FirstCheckInst;
Instruction *MemRuntimeCheck;
std::tie(FirstCheckInst, MemRuntimeCheck) =
Legal->getLAI()->addRuntimeChecks(BB->getTerminator());
if (!MemRuntimeCheck)
return;
// Create a new block containing the memory check.
BB->setName("vector.memcheck");
auto *NewBB = BB->splitBasicBlock(BB->getTerminator(), "vector.ph");
// Update dominator tree immediately if the generated block is a
// LoopBypassBlock because SCEV expansions to generate loop bypass
// checks may query it before the current function is finished.
DT->addNewBlock(NewBB, BB);
if (L->getParentLoop())
L->getParentLoop()->addBasicBlockToLoop(NewBB, *LI);
ReplaceInstWithInst(BB->getTerminator(),
BranchInst::Create(Bypass, NewBB, MemRuntimeCheck));
LoopBypassBlocks.push_back(BB);
AddedSafetyChecks = true;
// We currently don't use LoopVersioning for the actual loop cloning but we
// still use it to add the noalias metadata.
LVer = llvm::make_unique<LoopVersioning>(*Legal->getLAI(), OrigLoop, LI, DT,
PSE.getSE());
LVer->prepareNoAliasMetadata();
}
void InnerLoopVectorizer::createEmptyLoop() {
/*
In this function we generate a new loop. The new loop will contain
the vectorized instructions while the old loop will continue to run the
scalar remainder.
[ ] <-- loop iteration number check.
/ |
/ v
| [ ] <-- vector loop bypass (may consist of multiple blocks).
| / |
| / v
|| [ ] <-- vector pre header.
|| |
|| v
|| [ ] \
|| [ ]_| <-- vector loop.
|| |
| \ v
| >[ ] <--- middle-block.
| / |
| / |
| / v
-|- >[ ] <--- new preheader.
| |
| v
| [ ] \
| [ ]_| <-- old scalar loop to handle remainder.
\ |
\ v
>[ ] <-- exit block.
...
*/
BasicBlock *OldBasicBlock = OrigLoop->getHeader();
BasicBlock *VectorPH = OrigLoop->getLoopPreheader();
BasicBlock *ExitBlock = OrigLoop->getExitBlock();
assert(VectorPH && "Invalid loop structure");
assert(ExitBlock && "Must have an exit block");
// Some loops have a single integer induction variable, while other loops
// don't. One example is c++ iterators that often have multiple pointer
// induction variables. In the code below we also support a case where we
// don't have a single induction variable.
//
// We try to obtain an induction variable from the original loop as hard
// as possible. However if we don't find one that:
// - is an integer
// - counts from zero, stepping by one
// - is the size of the widest induction variable type
// then we create a new one.
OldInduction = Legal->getPrimaryInduction();
Type *IdxTy = Legal->getWidestInductionType();
// Split the single block loop into the two loop structure described above.
BasicBlock *VecBody =
VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.body");
BasicBlock *MiddleBlock =
VecBody->splitBasicBlock(VecBody->getTerminator(), "middle.block");
BasicBlock *ScalarPH =
MiddleBlock->splitBasicBlock(MiddleBlock->getTerminator(), "scalar.ph");
// Create and register the new vector loop.
Loop *Lp = new Loop();
Loop *ParentLoop = OrigLoop->getParentLoop();
if (ParentLoop) {
ParentLoop->addChildLoop(Lp);
ParentLoop->addBasicBlockToLoop(ScalarPH, *LI);
ParentLoop->addBasicBlockToLoop(MiddleBlock, *LI);
} else {
LI->addTopLevelLoop(Lp);
}
Lp->addBasicBlockToLoop(VecBody, *LI);
// Find the loop boundaries.
Value *Count = getOrCreateTripCount(Lp);
Value *StartIdx = ConstantInt::get(IdxTy, 0);
Value *Step = getOrCreateInductionStep(Lp);
// We need to test whether the backedge-taken count is uint##_max. Adding one
// to it will cause overflow and an incorrect loop trip count in the vector
// body. In case of overflow we want to directly jump to the scalar remainder
// loop.
emitMinimumIterationCountCheck(Lp, Step, ScalarPH);
// Now, compare the new count to zero. If it is zero skip the vector loop and
// jump to the scalar loop.
emitVectorLoopEnteredCheck(Lp, ScalarPH);
// Generate the code to check any assumptions that we've made for SCEV
// expressions.
emitSCEVChecks(Lp, ScalarPH);
// Generate the code that checks in runtime if arrays overlap. We put the
// checks into a separate block to make the more common case of few elements
// faster.
emitMemRuntimeChecks(Lp, ScalarPH);
// Generate the induction variable.
// The loop step is equal to the vectorization factor (num of SIMD elements)
// times the unroll factor (num of SIMD instructions).
Value *CountRoundDown = getOrCreateVectorTripCount(Lp);
Induction =
createInductionVariable(Lp, StartIdx, CountRoundDown, InductionStep,
getDebugLocFromInstOrOperands(OldInduction));
// We are going to resume the execution of the scalar loop.
// Go over all of the induction variables that we found and fix the
// PHIs that are left in the scalar version of the loop.
// The starting values of PHI nodes depend on the counter of the last
// iteration in the vectorized loop.
// If we come from a bypass edge then we need to start from the original
// start value.
// This variable saves the new starting index for the scalar loop. It is used
// to test if there are any tail iterations left once the vector loop has
// completed.
LoopVectorizationLegality::InductionList::iterator I, E;
LoopVectorizationLegality::InductionList *List = Legal->getInductionVars();
for (I = List->begin(), E = List->end(); I != E; ++I) {
PHINode *OrigPhi = I->first;
InductionDescriptor II = I->second;
// Create phi nodes to merge from the backedge-taken check block.
PHINode *BCResumeVal = PHINode::Create(
OrigPhi->getType(), 3, "bc.resume.val", ScalarPH->getTerminator());
Value *&EndValue = IVEndValues[OrigPhi];
if (OrigPhi == OldInduction) {
// We know what the end value is.
EndValue = CountRoundDown;
} else {
IRBuilder<> B(LoopBypassBlocks.back()->getTerminator());
Type *StepType = II.getStep()->getType();
Instruction::CastOps CastOp =
CastInst::getCastOpcode(CountRoundDown, true, StepType, true);
Value *CRD = B.CreateCast(CastOp, CountRoundDown, StepType, "cast.crd");
const DataLayout &DL = OrigLoop->getHeader()->getModule()->getDataLayout();
EndValue = II.transform(B, CRD, PSE.getSE(), DL);
EndValue->setName("ind.end");
}
// The new PHI merges the original incoming value, in case of a bypass,
// or the value at the end of the vectorized loop.
BCResumeVal->addIncoming(EndValue, MiddleBlock);
// Fix the scalar body counter (PHI node).
unsigned BlockIdx = OrigPhi->getBasicBlockIndex(ScalarPH);
// The old induction's phi node in the scalar body needs the truncated
// value.
for (unsigned I = 0, E = LoopBypassBlocks.size(); I != E; ++I)
BCResumeVal->addIncoming(II.getStartValue(), LoopBypassBlocks[I]);
OrigPhi->setIncomingValue(BlockIdx, BCResumeVal);
}
// Add a check in the middle block to see if we have completed
// all of the iterations in the first vector loop.
// If (N - N%VF) == N, then we *don't* need to run the remainder.
Value *CmpN =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, Count,
CountRoundDown, "cmp.n", MiddleBlock->getTerminator());
ReplaceInstWithInst(MiddleBlock->getTerminator(),
BranchInst::Create(ExitBlock, ScalarPH, CmpN));
// Get ready to start creating new instructions into the vectorized body.
Builder.SetInsertPoint(&*VecBody->getFirstInsertionPt());
// Save the state.
LoopVectorPreHeader = Lp->getLoopPreheader();
LoopScalarPreHeader = ScalarPH;
LoopMiddleBlock = MiddleBlock;
LoopExitBlock = ExitBlock;
LoopVectorBody.push_back(VecBody);
VecBodyPostDom = VecBody;
LoopScalarBody = OldBasicBlock;
// Keep all loop hints from the original loop on the vector loop (we'll
// replace the vectorizer-specific hints below).
if (MDNode *LID = OrigLoop->getLoopID())
Lp->setLoopID(LID);
LoopVectorizeHints Hints(Lp, true, *ORE);
Hints.setAlreadyVectorized();
}
void InnerLoopVectorizer::createEmptyLoopWithPredication() {
/*
In this function we generate a new loop. The new loop will contain
the vectorized instructions while the old loop will continue to run the
scalar remainder.
v
[ ] <-- Back-edge taken count overflow check.
/ \
| [ ] <-- vector loop bypass (may consist of multiple blocks).
| / \
| [ ] \ <-- vector pre header.
| | |
| />[ ] |
| |_[ ] | <-- vector loop.
| | |
| [ ] | <-- middle-block.
| | |
| [ ] | <-- return point from predicated loop.
| | |
|<---/ |
| [ ] <-- scalar preheader.
| |
| [ ]<\
| [ ]_| <-- old scalar loop to handle remainder.
| |
|<-------/
v
[ ] <-- exit block.
...
*/
assert(UsePredication && "predication required for this layout");
BasicBlock *OldBasicBlock = OrigLoop->getHeader();
BasicBlock *VectorPH = OrigLoop->getLoopPreheader();
BasicBlock *ExitBlock = OrigLoop->getExitBlock();
assert(VectorPH && "Invalid loop structure");
assert(ExitBlock && "Must have an exit block");
// Some loops have a single integer induction variable, while other loops
// don't. One example is c++ iterators that often have multiple pointer
// induction variables. In the code below we also support a case where we
// don't have a single induction variable.
//
// We try to obtain an induction variable from the original loop as hard
// as possible. However if we don't find one that:
// - is an integer
// - counts from zero, stepping by one
// - is the size of the widest induction variable type
// then we create a new one.
OldInduction = Legal->getPrimaryInduction();
Type *IdxTy = Legal->getWidestInductionType();
Type *PredTy = Builder.getInt1Ty();
Type *PredVecTy = VectorType::get(PredTy, VF, Scalable);
Constant *One = ConstantInt::get(IdxTy, 1);
// Split the single block loop into the two loop structure described above.
BasicBlock *VecBody =
VectorPH->splitBasicBlock(VectorPH->getTerminator(), "vector.body");
BasicBlock *MiddleBlock =
VecBody->splitBasicBlock(VecBody->getTerminator(), "middle.block");
BasicBlock *ScalarPH =
MiddleBlock->splitBasicBlock(MiddleBlock->getTerminator(), "scalar.ph");
// Create and register the new vector loop.
Loop* Lp = new Loop();
Loop *ParentLoop = OrigLoop->getParentLoop();
if (ParentLoop) {
ParentLoop->addChildLoop(Lp);
ParentLoop->addBasicBlockToLoop(ScalarPH, *LI);
ParentLoop->addBasicBlockToLoop(MiddleBlock, *LI);
} else {
LI->addTopLevelLoop(Lp);
}
Lp->addBasicBlockToLoop(VecBody, *LI);
// Find the loop boundaries.
Value *Count = getOrCreateTripCount(Lp);
Value *StartIdx = ConstantInt::get(IdxTy, 0);
getOrCreateInductionStep(Lp);
IdxEnd = Count;
// We need to test whether the backedge-taken count is uint##_max. Adding one
// to it will cause overflow and an incorrect loop trip count in the vector
// body. In case of overflow we want to directly jump to the scalar loop.
{
ScalarEvolution *SE = PSE.getSE();
const SCEV *BackedgeTakenCount = PSE.getBackedgeTakenCount();
Type *IdxTy = Legal->getWidestInductionType();
// The exit count might have the type of i64 while the phi is i32. This can
// happen if we have an induction variable that is sign extended before the
// compare. The only way that we get a backedge taken count is that the
// induction variable was signed and as such will not overflow. In such a
// case truncation is legal.
if (BackedgeTakenCount->getType()->getPrimitiveSizeInBits() >
IdxTy->getPrimitiveSizeInBits())
BackedgeTakenCount = SE->getTruncateOrNoop(BackedgeTakenCount, IdxTy);
BackedgeTakenCount = SE->getNoopOrZeroExtend(BackedgeTakenCount, IdxTy);
// If we know ahead of time that overflow is not possible we still plant
// the check but in a manner that is easily removable by a later pass.
APInt MaxTakenCount = SE->getUnsignedRange(BackedgeTakenCount).getUpper();
Constant *MinCount = ConstantInt::get(IdxTy, (MaxTakenCount + 1) == 0);
emitMinimumIterationCountCheck(Lp, MinCount, ScalarPH);
}
// Generate the code to check any assumptions that we've made for SCEV
// expressions.
emitSCEVChecks(Lp, ScalarPH);
// Generate the code that checks in runtime if arrays overlap. We put the
// checks into a separate block to make the more common case of few elements
// faster.
emitMemRuntimeChecks(Lp, ScalarPH);
// Record the exit value of induction variables for use by fixupIVUsers.
for (auto &Entry : *Legal->getInductionVars()) {
PHINode *OrigPhi = Entry.first;
InductionDescriptor II = Entry.second;
IRBuilder<> B(LoopBypassBlocks.back()->getTerminator());
auto StepType = II.getStep()->getType();
auto CastOp = CastInst::getCastOpcode(IdxEnd, true, StepType, true);
auto CRD = B.CreateCast(CastOp, IdxEnd, StepType, "cast.crd");
const DataLayout &DL = OrigLoop->getHeader()->getModule()->getDataLayout();
Value *&EndValue = IVEndValues[OrigPhi];
EndValue = II.transform(B, CRD, PSE.getSE(), DL);
EndValue->setName("ind.end");
}
// ***************************************************************************
// Start of vector.ph
// ***************************************************************************
Builder.SetInsertPoint(&*Lp->getLoopPreheader()->getTerminator());
setDebugLocFromInst(Builder, getDebugLocFromInstOrOperands(OldInduction));
IdxEndV = Builder.CreateVectorSplat({VF, Scalable}, Count, "wide.end.idx");
// Create the loop's entry predicate taking integer overflow into account.
VectorParts EntryPreds;
Value *TV = UndefValue::get(VectorType::get(IdxTy, VF, Scalable));
Value *RuntimeVF = Builder.CreateElementCount(IdxTy, TV);
// Chain the entry predicates taking the UF into account
Value *PropPred = ConstantInt::getTrue(PredVecTy);
for (unsigned i = 0; i < UF; ++i) {
Value *Step = Builder.CreateMul(RuntimeVF, ConstantInt::get(IdxTy, i));
Value *Idx = Builder.CreateAdd(StartIdx, Step);
Value *SV = Builder.CreateSeriesVector({VF,Scalable}, Idx, One);
Value *Cmp = Builder.CreateICmpULT(SV, IdxEndV);
PropPred = Builder.CreatePropFF(PropPred, Cmp, "predicate.entry");
EntryPreds.push_back(PropPred);
}
// ***************************************************************************
// End of vector.ph
// ***************************************************************************
// ***************************************************************************
// Start of vector.body
// ***************************************************************************
BasicBlock *Header = Lp->getHeader();
BasicBlock *Latch = Lp->getLoopLatch();
// As we're just creating this loop, it's possible no latch exists
// yet. If so, use the header as this will be a single block loop.
if (!Latch)
Latch = Header;
Builder.SetInsertPoint(&*Header->getFirstInsertionPt());
setDebugLocFromInst(Builder, getDebugLocFromInstOrOperands(OldInduction));
// Generate the induction variable.
Induction = Builder.CreatePHI(IdxTy, 2, "index");
for (unsigned i = 0; i < UF; ++i)
Predicate.push_back(Builder.CreatePHI(PredVecTy, 2, "predicate"));
// These Phis have two incoming values, but right now we only add the
// one coming from the preheader. The other (from the loop latch block)
// will be added in 'patchLatchBranch', after everything else has been
// vectorized. This allows predicates from first-faulting loads or other
// instructions to be added in before finalizing the phi.
Induction->addIncoming(StartIdx, Lp->getLoopPreheader());
for (unsigned i = 0; i < UF; ++i)
Predicate[i]->addIncoming(EntryPreds[i], Lp->getLoopPreheader());
Builder.SetInsertPoint(Latch->getTerminator());
// We don't yet have a condition for the branch, since it may depend on
// instructions within the loop (beyond just the trip count, if any).
// As above, this will be added in 'patchLatchBranch'.
Value *ICmp = UndefValue::get(Builder.getInt1Ty());
LatchBranch = Builder.CreateCondBr(ICmp, Header, Lp->getExitBlock());
// Now we have two terminators. Remove the old one from the block.
Latch->getTerminator()->eraseFromParent();
// ***************************************************************************
// End of vector.body
// ***************************************************************************
// ***************************************************************************
// Start of reduction.loop.ret
// ***************************************************************************
// The vector body processes all elements so after the reduction we are done.
Instruction *OldTerm = MiddleBlock->getTerminator();
BranchInst::Create(ExitBlock, OldTerm);
OldTerm->eraseFromParent();
// ***************************************************************************
// End of reduction.loop.ret
// ***************************************************************************
// Get ready to start creating new instructions into the vectorized body.
Builder.SetInsertPoint(&*VecBody->getFirstInsertionPt());
// Save the state.
LoopVectorPreHeader = Lp->getLoopPreheader();
LoopScalarPreHeader = ScalarPH;
LoopMiddleBlock = MiddleBlock;
LoopExitBlock = ExitBlock;
LoopVectorBody.push_back(VecBody);
VecBodyPostDom = VecBody;
LoopScalarBody = OldBasicBlock;
LoopVectorizeHints Hints(Lp, true, *ORE);
Hints.setAlreadyVectorized();
}
// Fix up external users of the induction variable. At this point, we are
// in LCSSA form, with all external PHIs that use the IV having one input value,
// coming from the remainder loop. We need those PHIs to also have a correct
// value for the IV when arriving directly from the middle block.
void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
const InductionDescriptor &II,
Value *CountRoundDown, Value *EndValue,
BasicBlock *MiddleBlock) {
// There are two kinds of external IV usages - those that use the value
// computed in the last iteration (the PHI) and those that use the penultimate
// value (the value that feeds into the phi from the loop latch).
// We allow both, but they, obviously, have different values.
assert(OrigLoop->getExitBlock() && "Expected a single exit block");
DenseMap<Value *, Value *> MissingVals;
// An external user of the last iteration's value should see the value that
// the remainder loop uses to initialize its own IV.
Value *PostInc = OrigPhi->getIncomingValueForBlock(OrigLoop->getLoopLatch());
for (User *U : PostInc->users()) {
Instruction *UI = cast<Instruction>(U);
if (!OrigLoop->contains(UI)) {
assert(isa<PHINode>(UI) && "Expected LCSSA form");
MissingVals[UI] = EndValue;
}
}
// An external user of the penultimate value need to see EndValue - Step.
// The simplest way to get this is to recompute it from the constituent SCEVs,
// that is Start + (Step * (CRD - 1)).
for (User *U : OrigPhi->users()) {
auto *UI = cast<Instruction>(U);
if (!OrigLoop->contains(UI)) {
const DataLayout &DL =
OrigLoop->getHeader()->getModule()->getDataLayout();
assert(isa<PHINode>(UI) && "Expected LCSSA form");
IRBuilder<> B(MiddleBlock->getTerminator());
Value *CountMinusOne = B.CreateSub(
CountRoundDown, ConstantInt::get(CountRoundDown->getType(), 1));
Value *CMO = B.CreateSExtOrTrunc(CountMinusOne, II.getStep()->getType(),
"cast.cmo");
Value *Escape = II.transform(B, CMO, PSE.getSE(), DL);
Escape->setName("ind.escape");
MissingVals[UI] = Escape;
}
}
for (auto &I : MissingVals) {
PHINode *PHI = cast<PHINode>(I.first);
// One corner case we have to handle is two IVs "chasing" each-other,
// that is %IV2 = phi [...], [ %IV1, %latch ]
// In this case, if IV1 has an external use, we need to avoid adding both
// "last value of IV1" and "penultimate value of IV2". So, verify that we
// don't already have an incoming value for the middle block.
if (PHI->getBasicBlockIndex(MiddleBlock) == -1)
PHI->addIncoming(I.second, MiddleBlock);
}
}
namespace {
struct CSEDenseMapInfo {
static bool canHandle(const Instruction *I) {
return isa<InsertElementInst>(I) || isa<ExtractElementInst>(I) ||
isa<ShuffleVectorInst>(I) || isa<GetElementPtrInst>(I);
}
static inline Instruction *getEmptyKey() {
return DenseMapInfo<Instruction *>::getEmptyKey();
}
static inline Instruction *getTombstoneKey() {
return DenseMapInfo<Instruction *>::getTombstoneKey();
}
static unsigned getHashValue(const Instruction *I) {
assert(canHandle(I) && "Unknown instruction!");
return hash_combine(I->getOpcode(), hash_combine_range(I->value_op_begin(),
I->value_op_end()));
}
static bool isEqual(const Instruction *LHS, const Instruction *RHS) {
if (LHS == getEmptyKey() || RHS == getEmptyKey() ||
LHS == getTombstoneKey() || RHS == getTombstoneKey())
return LHS == RHS;
return LHS->isIdenticalTo(RHS);
}
};
}
///\brief Perform cse of induction variable instructions.
void InnerLoopVectorizer::CSE(SmallVector<BasicBlock *, 4> &BBs,
SmallSet<BasicBlock *, 2> &PredBlocks) {
// Perform simple cse.
SmallDenseMap<Instruction *, Instruction *, 4, CSEDenseMapInfo> CSEMap;
for (unsigned i = 0, e = BBs.size(); i != e; ++i) {
BasicBlock *BB = BBs[i];
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
Instruction *In = &*I++;
if (!CSEDenseMapInfo::canHandle(In))
continue;
// Check if we can replace this instruction with any of the
// visited instructions.
if (Instruction *V = CSEMap.lookup(In)) {
In->replaceAllUsesWith(V);
In->eraseFromParent();
continue;
}
// Ignore instructions in conditional blocks. We create "if (pred) a[i] =
// ...;" blocks for predicated stores. Every second block is a predicated
// block.
if (PredBlocks.count(BBs[i]))
continue;
// Check if we can replace this instruction with any of the
// visited instructions.
if (Instruction *V = CSEMap.lookup(In)) {
In->replaceAllUsesWith(V);
In->eraseFromParent();
continue;
}
CSEMap[In] = In;
}
}
}
/// Estimate the overhead of scalarizing a value. Insert and Extract are set if
/// the result needs to be inserted and/or extracted from vectors.
static unsigned getScalarizationOverhead(Instruction *I, VectorizationFactor VF,
const TargetTransformInfo &TTI) {
if (VF.Width == 1)
return 0;
unsigned Cost = 0;
Type *RetTy = ToVectorTy(I->getType(), VF);
if (!RetTy->isVoidTy() &&
(!isa<LoadInst>(I) || !TTI.supportsEfficientVectorElementLoadStore()))
Cost += TTI.getScalarizationOverhead(RetTy, true, false);
if (CallInst *CI = dyn_cast<CallInst>(I)) {
SmallVector<const Value *, 4> Operands(CI->arg_operands());
Cost += TTI.getOperandsScalarizationOverhead(Operands, VF.Width);
} else if (!isa<StoreInst>(I) ||
!TTI.supportsEfficientVectorElementLoadStore()) {
SmallVector<const Value *, 4> Operands(I->operand_values());
Cost += TTI.getOperandsScalarizationOverhead(Operands, VF.Width);
}
return Cost;
}
// Estimate cost of a call instruction CI if it were vectorized with factor VF.
// Return the cost of the instruction, including scalarization overhead if it's
// needed. The flag NeedToScalarize shows if the call needs to be scalarized -
// i.e. either vector version isn't available, or is too expensive.
static unsigned getVectorCallCost(CallInst *CI, VectorizationFactor VF,
const TargetTransformInfo &TTI,
const TargetLibraryInfo *TLI,
LoopVectorizationLegality &Legal,
bool &NeedToScalarize) {
if (VectorizeMemset && isa<MemSetInst>(CI)) {
auto MSI = cast<MemSetInst> (CI);
const auto Length = MSI->getLength();
const auto IsVolatile = MSI->isVolatile();
const auto Alignment = MSI->getAlignmentCst()->getZExtValue();
auto CL = dyn_cast<ConstantInt>(Length);
auto CLength = CL->getZExtValue();
assert (CL && ( CLength% Alignment == 0)
&& ((CLength / Alignment) <= VectorizerMemSetThreshold)
&& !IsVolatile && "Invalid memset call.");
return CLength / Alignment;
}
Function *F = CI->getCalledFunction();
StringRef FnName = CI->getCalledFunction()->getName();
Type *ScalarRetTy = CI->getType();
SmallVector<Type *, 4> Tys, ScalarTys;
for (auto &ArgOp : CI->arg_operands())
ScalarTys.push_back(ArgOp->getType());
// Estimate cost of scalarized vector call. The source operands are assumed
// to be vectors, so we need to extract individual elements from there,
// execute VF.Width scalar calls, and then gather the result into the vector return
// value.
const unsigned ScalarCallCost = TTI.getCallInstrCost(F, ScalarRetTy, ScalarTys);
if (VF.Width == 1)
return ScalarCallCost;
// Compute corresponding vector type for return value and arguments.
Type *RetTy = ToVectorTy(ScalarRetTy, VF);
for (auto &Op : CI->arg_operands()) {
Type *ScalarTy = Op->getType();
if (ScalarTy->isPointerTy() && Legal.isConsecutivePtr(Op))
Tys.push_back(ScalarTy);
else
Tys.push_back(ToVectorTy(ScalarTy, VF));
}
if (!VF.isFixed) {
IRBuilder<> Builder(CI);
Type *PredTy = Builder.getInt1Ty();
Tys.push_back(ToVectorTy(PredTy, VF));
}
// Compute costs of unpacking argument values for the scalar calls and
// packing the return values to a vector.
unsigned ScalarizationCost = getScalarizationOverhead(CI, VF, TTI);
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i)
ScalarizationCost += getScalarizationOverhead(CI, VF, TTI);
unsigned Cost = ScalarCallCost * VF.Width + ScalarizationCost;
// If we can't emit a vector call for this function, then the currently found
// cost is the cost we need to return.
NeedToScalarize = true;
FunctionType *FTy = FunctionType::get(RetTy, Tys, false);
if (TLI && (TLI->getVectorizedFunction(FnName, VF.Width, FTy) != ""))
return ScalarCallCost;
if (!TLI || !TLI->isFunctionVectorizable(FnName, VF.Width, FTy) ||
CI->isNoBuiltin())
return Cost;
// If the corresponding vector cost is cheaper, return its cost.
unsigned VectorCallCost = TTI.getCallInstrCost(nullptr, RetTy, Tys);
if (VectorCallCost < Cost) {
NeedToScalarize = false;
return VectorCallCost;
}
return Cost;
}
// Estimate cost of an intrinsic call instruction CI if it were vectorized with
// factor VF. Return the cost of the instruction, including scalarization
// overhead if it's needed.
static unsigned getVectorIntrinsicCost(CallInst *CI, unsigned VF,
const TargetTransformInfo &TTI,
const TargetLibraryInfo *TLI) {
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
assert(ID && "Expected intrinsic call!");
Type *RetTy = ToVectorTy(CI->getType(), VF, false);
SmallVector<Type *, 4> Tys;
for (unsigned i = 0, ie = CI->getNumArgOperands(); i != ie; ++i)
Tys.push_back(ToVectorTy(CI->getArgOperand(i)->getType(), VF, false));
FastMathFlags FMF;
if (auto *FPMO = dyn_cast<FPMathOperator>(CI))
FMF = FPMO->getFastMathFlags();
return TTI.getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
}
static Type *smallestIntegerVectorType(Type *T1, Type *T2) {
IntegerType *I1 = cast<IntegerType>(T1->getVectorElementType());
IntegerType *I2 = cast<IntegerType>(T2->getVectorElementType());
return I1->getBitWidth() < I2->getBitWidth() ? T1 : T2;
}
static Type *largestIntegerVectorType(Type *T1, Type *T2) {
IntegerType *I1 = cast<IntegerType>(T1->getVectorElementType());
IntegerType *I2 = cast<IntegerType>(T2->getVectorElementType());
return I1->getBitWidth() > I2->getBitWidth() ? T1 : T2;
}
void InnerLoopVectorizer::truncateToMinimalBitwidths() {
// For every instruction `I` in MinBWs, truncate the operands, create a
// truncated version of `I` and reextend its result. InstCombine runs
// later and will remove any ext/trunc pairs.
//
SmallPtrSet<Value *, 4> Erased;
for (auto &KV : MinBWs) {
VectorParts &Parts = WidenMap.get(KV.first);
for (Value *&I : Parts) {
if (Erased.count(I) || I->use_empty())
continue;
auto *OriginalTy = cast<VectorType>(I->getType());
Type *ScalarTruncatedTy =
IntegerType::get(OriginalTy->getContext(), KV.second);
Type *TruncatedTy = VectorType::get(ScalarTruncatedTy,
OriginalTy->getElementCount());
if (TruncatedTy == OriginalTy)
continue;
if (!isa<Instruction>(I))
continue;
IRBuilder<> B(cast<Instruction>(I));
auto ShrinkOperand = [&](Value *V) -> Value * {
if (auto *ZI = dyn_cast<ZExtInst>(V))
if (ZI->getSrcTy() == TruncatedTy)
return ZI->getOperand(0);
return B.CreateZExtOrTrunc(V, TruncatedTy);
};
// The actual instruction modification depends on the instruction type,
// unfortunately.
Value *NewI = nullptr;
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
NewI = B.CreateBinOp(BO->getOpcode(), ShrinkOperand(BO->getOperand(0)),
ShrinkOperand(BO->getOperand(1)));
cast<BinaryOperator>(NewI)->copyIRFlags(I);
} else if (ICmpInst *CI = dyn_cast<ICmpInst>(I)) {
NewI =
B.CreateICmp(CI->getPredicate(), ShrinkOperand(CI->getOperand(0)),
ShrinkOperand(CI->getOperand(1)));
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
NewI = B.CreateSelect(SI->getCondition(),
ShrinkOperand(SI->getTrueValue()),
ShrinkOperand(SI->getFalseValue()));
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
switch (CI->getOpcode()) {
default:
llvm_unreachable("Unhandled cast!");
case Instruction::Trunc:
NewI = ShrinkOperand(CI->getOperand(0));
break;
case Instruction::SExt:
NewI = B.CreateSExtOrTrunc(
CI->getOperand(0),
smallestIntegerVectorType(OriginalTy, TruncatedTy));
break;
case Instruction::ZExt:
NewI = B.CreateZExtOrTrunc(
CI->getOperand(0),
smallestIntegerVectorType(OriginalTy, TruncatedTy));
break;
}
} else if (ShuffleVectorInst *SI = dyn_cast<ShuffleVectorInst>(I)) {
auto VTy0 = cast<VectorType>(SI->getOperand(0)->getType());
auto Elements0 = VTy0->getElementCount();
auto *O0 = B.CreateZExtOrTrunc(
SI->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements0));
auto VTy1 = cast<VectorType>(SI->getOperand(1)->getType());
auto Elements1 = VTy1->getElementCount();
auto *O1 = B.CreateZExtOrTrunc(
SI->getOperand(1), VectorType::get(ScalarTruncatedTy, Elements1));
NewI = B.CreateShuffleVector(O0, O1, SI->getMask());
} else if (isa<LoadInst>(I) || isa<CallInst>(I)) {
// Don't do anything with the operands, just extend the result.
continue;
} else if (auto *IE = dyn_cast<InsertElementInst>(I)) {
auto Elements = IE->getOperand(0)->getType()->getVectorNumElements();
auto *O0 = B.CreateZExtOrTrunc(
IE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements));
auto *O1 = B.CreateZExtOrTrunc(IE->getOperand(1), ScalarTruncatedTy);
NewI = B.CreateInsertElement(O0, O1, IE->getOperand(2));
} else if (auto *EE = dyn_cast<ExtractElementInst>(I)) {
auto Elements = EE->getOperand(0)->getType()->getVectorNumElements();
auto *O0 = B.CreateZExtOrTrunc(
EE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements));
NewI = B.CreateExtractElement(O0, EE->getOperand(2));
} else {
llvm_unreachable("Unhandled instruction type!");
}
// Lastly, extend the result.
NewI->takeName(cast<Instruction>(I));
Value *Res = B.CreateZExtOrTrunc(NewI, OriginalTy);
I->replaceAllUsesWith(Res);
cast<Instruction>(I)->eraseFromParent();
Erased.insert(I);
I = Res;
}
}
// We'll have created a bunch of ZExts that are now parentless. Clean up.
for (auto &KV : MinBWs) {
VectorParts &Parts = WidenMap.get(KV.first);
for (Value *&I : Parts) {
ZExtInst *Inst = dyn_cast<ZExtInst>(I);
if (Inst && Inst->use_empty()) {
Value *NewI = Inst->getOperand(0);
Inst->eraseFromParent();
I = NewI;
}
}
}
}
void InnerLoopVectorizer::vectorizeLoop() {
//===------------------------------------------------===//
//
// Notice: any optimization or new instruction that go
// into the code below should be also be implemented in
// the cost-model.
//
//===------------------------------------------------===//
Constant *Zero = Builder.getInt32(0);
// In order to support recurrences we need to be able to vectorize Phi nodes.
// Phi nodes have cycles, so we need to vectorize them in two stages. First,
// we create a new vector PHI node with no incoming edges. We use this value
// when we vectorize all of the instructions that use the PHI. Next, after
// all of the instructions in the block are complete we add the new incoming
// edges to the PHI. At this point all of the instructions in the basic block
// are vectorized, so we can use them to construct the PHI.
PhiVector PHIsToFix;
// Move instructions to handle first-order recurrences.
DenseMap<Instruction *, Instruction *> SinkAfter = Legal->getSinkAfter();
for (auto &Entry : SinkAfter) {
Entry.first->removeFromParent();
Entry.first->insertAfter(Entry.second);
DEBUG(dbgs() << "Sinking" << *Entry.first << " after" << *Entry.second
<< " to vectorize a 1st order recurrence.\n");
}
// Scan the loop in a topological order to ensure that defs are vectorized
// before users.
LoopBlocksDFS DFS(OrigLoop);
DFS.perform(LI);
// Vectorize all of the blocks in the original loop.
for (LoopBlocksDFS::RPOIterator bb = DFS.beginRPO(), be = DFS.endRPO();
bb != be; ++bb)
vectorizeBlockInLoop(*bb, &PHIsToFix);
// When using predication not all elements will be modified during the current
// iteration and so we must iterate through the reduction variables selecting
// between the original and new values for each element.
if (UsePredication) {
for (auto *RdxPhi : PHIsToFix) {
assert(RdxPhi && "Unable to recover vectorized PHI");
if (Legal->isFirstOrderRecurrence(RdxPhi))
continue;
// Find the reduction variable descriptor.
assert(Legal->getReductionVars()->count(RdxPhi) &&
"Unable to find the reduction variable");
RecurrenceDescriptor RdxDesc = (*Legal->getReductionVars())[RdxPhi];
VectorParts &VecRdxPhi = WidenMap.get(RdxPhi);
Value * LoopExitInstr = RdxDesc.getLoopExitInstr();
VectorParts &VectorExit = getVectorValue(LoopExitInstr);
for (unsigned Part = 0; Part < UF; ++Part) {
if (!RdxDesc.isOrdered()) {
Instruction *Merge = SelectInst::Create(Predicate[Part],
VectorExit[Part],
VecRdxPhi[Part]);
Merge->insertAfter(cast<Instruction>(VectorExit[Part]));
VectorExit[Part] = Merge;
}
}
}
}
// Insert truncates and extends for any truncated instructions as hints to
// InstCombine.
if (VF > 1)
truncateToMinimalBitwidths();
// At this point every instruction in the original loop is widened to a
// vector form. Now we need to fix the recurrences in PHIsToFix. These PHI
// nodes are currently empty because we did not want to introduce cycles.
// This is the second stage of vectorizing recurrences.
for (PHINode *Phi : PHIsToFix) {
assert(Phi && "Unable to recover vectorized PHI");
// Handle first-order recurrences that need to be fixed.
if (Legal->isFirstOrderRecurrence(Phi)) {
fixFirstOrderRecurrence(Phi);
continue;
}
// If the phi node is not a first-order recurrence, it must be a reduction.
// Get it's reduction variable descriptor.
assert(Legal->isReductionVariable(Phi) &&
"Unable to find the reduction variable");
RecurrenceDescriptor RdxDesc = (*Legal->getReductionVars())[Phi];
RecurrenceDescriptor::RecurrenceKind RK = RdxDesc.getRecurrenceKind();
TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue();
Instruction *LoopExitInst = RdxDesc.getLoopExitInstr();
RecurrenceDescriptor::MinMaxRecurrenceKind MinMaxKind =
RdxDesc.getMinMaxRecurrenceKind();
setDebugLocFromInst(Builder, ReductionStartValue);
// We need to generate a reduction vector from the incoming scalar.
// To do so, we need to generate the 'identity' vector and override
// one of the elements with the incoming scalar reduction. We need
// to do it in the vector-loop preheader.
if (UsePredication)
Builder.SetInsertPoint(LoopBypassBlocks[0]->getTerminator());
else
Builder.SetInsertPoint(LoopBypassBlocks[1]->getTerminator());
// This is the vector-clone of the value that leaves the loop.
VectorParts &VectorExit = getVectorValue(LoopExitInst);
Type *VecTy = VectorExit[0]->getType();
// Find the reduction identity variable. Zero for addition, or, xor,
// one for multiplication, -1 for And.
Value *Identity;
Value *VectorStart;
if (RK == RecurrenceDescriptor::RK_IntegerMinMax ||
RK == RecurrenceDescriptor::RK_FloatMinMax) {
// MinMax reduction have the start value as their identify.
if (VF == 1) {
VectorStart = Identity = ReductionStartValue;
} else {
VectorStart = Identity =
Builder.CreateVectorSplat({VF, Scalable},
RdxDesc.getRecurrenceStartValue(),
"minmax.ident");
}
} else {
// Handle other reduction kinds:
Constant *Iden = RecurrenceDescriptor::getRecurrenceIdentity(
RK, VecTy->getScalarType());
if (VF == 1) {
Identity = Iden;
// This vector is the Identity vector where the first element is the
// incoming scalar reduction.
VectorStart = ReductionStartValue;
} else {
Identity = ConstantVector::getSplat({VF, Scalable}, Iden);
// This vector is the Identity vector where the first element is the
// incoming scalar reduction.
VectorStart =
Builder.CreateInsertElement(Identity, ReductionStartValue, Zero);
}
}
// Fix the vector-loop phi.
// Reductions do not have to start at zero. They can start with
// any loop invariant values.
VectorParts &VecRdxPhi = WidenMap.get(Phi);
BasicBlock *Latch = OrigLoop->getLoopLatch();
Value *LoopVal = Phi->getIncomingValueForBlock(Latch);
VectorParts &Val = getVectorValue(LoopVal);
for (unsigned part = 0; part < UF; ++part) {
// Only add the reduction start value to the first unroll part.
Value *StartVal = (part == 0) ? VectorStart : Identity;
Value *NewVal = Val[part];
if (RdxDesc.isOrdered() && VF > 1) {
StartVal = Builder.CreateExtractElement(StartVal,
Builder.getInt32(0));
NewVal = Val[UF-1];
}
cast<PHINode>(VecRdxPhi[part])
->addIncoming(StartVal, LoopVectorPreHeader);
cast<PHINode>(VecRdxPhi[part])
->addIncoming(NewVal, LoopVectorBody.back());
}
// Before each round, move the insertion point right between
// the PHIs and the values we are going to write.
// This allows us to write both PHINodes and the extractelement
// instructions.
Builder.SetInsertPoint(&*LoopMiddleBlock->getFirstInsertionPt());
VectorParts RdxParts = getVectorValue(LoopExitInst);
setDebugLocFromInst(Builder, LoopExitInst);
// If the vector reduction can be performed in a smaller type, we truncate
// then extend the loop exit value to enable InstCombine to evaluate the
// entire expression in the smaller type.
if (VF > 1 && Phi->getType() != RdxDesc.getRecurrenceType()) {
Type *RdxVecTy =
VectorType::get(RdxDesc.getRecurrenceType(), VF, Scalable);
Builder.SetInsertPoint(LoopVectorBody.back()->getTerminator());
for (unsigned part = 0; part < UF; ++part) {
Value *Trunc = Builder.CreateTrunc(RdxParts[part], RdxVecTy);
Value *Extnd = RdxDesc.isSigned() ? Builder.CreateSExt(Trunc, VecTy)
: Builder.CreateZExt(Trunc, VecTy);
for (Value::user_iterator UI = RdxParts[part]->user_begin();
UI != RdxParts[part]->user_end();)
if (*UI != Trunc) {
(*UI++)->replaceUsesOfWith(RdxParts[part], Extnd);
RdxParts[part] = Extnd;
} else {
++UI;
}
}
Builder.SetInsertPoint(&*LoopMiddleBlock->getFirstInsertionPt());
for (unsigned part = 0; part < UF; ++part)
RdxParts[part] = Builder.CreateTrunc(RdxParts[part], RdxVecTy);
}
// Reduce all of the unrolled parts into a single vector.
Value *ReducedPartRdx = RdxParts[0];
unsigned Op = RecurrenceDescriptor::getRecurrenceBinOp(RK);
setDebugLocFromInst(Builder, ReducedPartRdx);
if (!RdxDesc.isOrdered()) {
for (unsigned part = 1; part < UF; ++part) {
if (Op != Instruction::ICmp && Op != Instruction::FCmp)
// Floating point operations had to be 'fast' to enable the reduction.
ReducedPartRdx = addFastMathFlag(
Builder.CreateBinOp((Instruction::BinaryOps)Op, RdxParts[part],
ReducedPartRdx, "bin.rdx"));
else
ReducedPartRdx = RecurrenceDescriptor::createMinMaxOp(
Builder, MinMaxKind, ReducedPartRdx, RdxParts[part]);
}
} else {
// for ordered reduction get the result of the last unrolled
// instruction
ReducedPartRdx=RdxParts[UF-1];
}
if ((VF > 1) && !isScalable() && !RdxDesc.isOrdered()) {
// VF is a power of 2 so we can emit the reduction using log2(VF) shuffles
// and vector ops, reducing the set of values being computed by half each
// round.
assert(isPowerOf2_32(VF) &&
"Reduction emission only supported for pow2 vectors!");
Value *TmpVec = ReducedPartRdx;
SmallVector<Constant *, 32> ShuffleMask(VF, nullptr);
for (unsigned i = VF; i != 1; i >>= 1) {
// Move the upper half of the vector to the lower half.
for (unsigned j = 0; j != i / 2; ++j)
ShuffleMask[j] = Builder.getInt32(i / 2 + j);
// Fill the rest of the mask with undef.
std::fill(&ShuffleMask[i / 2], ShuffleMask.end(),
UndefValue::get(Builder.getInt32Ty()));
Value *Shuf = Builder.CreateShuffleVector(
TmpVec, UndefValue::get(TmpVec->getType()),
ConstantVector::get(ShuffleMask), "rdx.shuf");
if (Op != Instruction::ICmp && Op != Instruction::FCmp) {
// Floating point operations had to be 'fast' to enable the reduction.
TmpVec = addFastMathFlag(Builder.CreateBinOp(
(Instruction::BinaryOps)Op, TmpVec, Shuf, "bin.rdx"));
}
else
TmpVec = RecurrenceDescriptor::createMinMaxOp(Builder, MinMaxKind,
TmpVec, Shuf);
}
// The result is in the first element of the vector.
ReducedPartRdx =
Builder.CreateExtractElement(TmpVec, Builder.getInt32(0));
}
// Compute vector reduction for scalable vectors
if ((VF > 1) && isScalable() && !RdxDesc.isOrdered()) {
bool NoNaN = Legal->hasNoNaNAttr();
ReducedPartRdx =
createTargetReduction(Builder, TTI, RdxDesc, ReducedPartRdx, NoNaN);
}
if (VF > 1) {
// If the reduction can be performed in a smaller type, we need to extend
// the reduction to the wider type before we branch to the original loop.
if (Phi->getType() != RdxDesc.getRecurrenceType())
ReducedPartRdx =
RdxDesc.isSigned()
? Builder.CreateSExt(ReducedPartRdx, Phi->getType())
: Builder.CreateZExt(ReducedPartRdx, Phi->getType());
}
// Create a phi node that merges control-flow from the backedge-taken check
// block and the middle block.
PHINode *BCBlockPhi = PHINode::Create(Phi->getType(), 2, "bc.merge.rdx",
LoopScalarPreHeader->getTerminator());
for (unsigned I = 0, E = LoopBypassBlocks.size(); I != E; ++I)
BCBlockPhi->addIncoming(ReductionStartValue, LoopBypassBlocks[I]);
// When using predication the vector loop performs all iterations.
if (!UsePredication)
BCBlockPhi->addIncoming(ReducedPartRdx, LoopMiddleBlock);
// If there were stores of the reduction value to a uniform memory address
// inside the loop, create the final store here.
if (StoreInst *SI = RdxDesc.IntermediateStore) {
Builder.SetInsertPoint(LoopMiddleBlock->getTerminator());
StoreInst *NewSI = Builder.CreateStore(ReducedPartRdx,
SI->getPointerOperand());
propagateMetadata(NewSI, SI);
// If the reduction value is used in other places,
// then let the code below create PHI's for that.
}
// Now, we need to fix the users of the reduction variable
// inside and outside of the scalar remainder loop.
// We know that the loop is in LCSSA form. We need to update the
// PHI nodes in the exit blocks.
for (BasicBlock::iterator LEI = LoopExitBlock->begin(),
LEE = LoopExitBlock->end();
LEI != LEE; ++LEI) {
PHINode *LCSSAPhi = dyn_cast<PHINode>(LEI);
if (!LCSSAPhi)
break;
// All PHINodes need to have a single entry edge, or two if
// we already fixed them.
assert(LCSSAPhi->getNumIncomingValues() < 3 && "Invalid LCSSA PHI");
// We found our reduction value exit-PHI. Update it with the
// incoming bypass edge.
if (LCSSAPhi->getIncomingValue(0) == LoopExitInst) {
// Add an edge coming from the bypass.
LCSSAPhi->addIncoming(ReducedPartRdx, LoopMiddleBlock);
}
} // end of the LCSSA phi scan.
// Fix the scalar loop reduction variable with the incoming reduction sum
// from the vector body and from the backedge value.
int IncomingEdgeBlockIdx =
Phi->getBasicBlockIndex(OrigLoop->getLoopLatch());
assert(IncomingEdgeBlockIdx >= 0 && "Invalid block index");
// Pick the other block.
int SelfEdgeBlockIdx = (IncomingEdgeBlockIdx ? 0 : 1);
Phi->setIncomingValue(SelfEdgeBlockIdx, BCBlockPhi);
Phi->setIncomingValue(IncomingEdgeBlockIdx, LoopExitInst);
} // end of for each Phi in PHIsToFix.
// Make sure DomTree is updated.
updateAnalysis();
// Fix-up external users of the induction variables.
for (auto &Entry : *Legal->getInductionVars())
fixupIVUsers(Entry.first, Entry.second,
getOrCreateVectorTripCount(LI->getLoopFor(LoopVectorBody.front())),
IVEndValues[Entry.first], LoopMiddleBlock);
fixLCSSAPHIs();
// Predicate any stores.
for (auto KV : PredicatedStores) {
BasicBlock::iterator I(KV.first);
auto *BB = SplitBlock(I->getParent(), &*std::next(I), DT, LI);
auto *T = SplitBlockAndInsertIfThen(KV.second, &*I, /*Unreachable=*/false,
/*BranchWeights=*/nullptr, DT, LI);
I->moveBefore(T);
I->getParent()->setName("pred.store.if");
BB->setName("pred.store.continue");
}
DEBUG(DT->verifyDomTree());
// Remove redundant induction instructions.
CSE(LoopVectorBody, PredicatedBlocks);
}
void InnerLoopVectorizer::fixFirstOrderRecurrence(PHINode *Phi) {
// This is the second phase of vectorizing first-order recurrences. An
// overview of the transformation is described below. Suppose we have the
// following loop.
//
// for (int i = 0; i < n; ++i)
// b[i] = a[i] - a[i - 1];
//
// There is a first-order recurrence on "a". For this loop, the shorthand
// scalar IR looks like:
//
// scalar.ph:
// s_init = a[-1]
// br scalar.body
//
// scalar.body:
// i = phi [0, scalar.ph], [i+1, scalar.body]
// s1 = phi [s_init, scalar.ph], [s2, scalar.body]
// s2 = a[i]
// b[i] = s2 - s1
// br cond, scalar.body, ...
//
// In this example, s1 is a recurrence because it's value depends on the
// previous iteration. In the first phase of vectorization, we created a
// temporary value for s1. We now complete the vectorization and produce the
// shorthand vector IR shown below (for VF = 4, UF = 1).
//
// vector.ph:
// v_init = vector(..., ..., ..., a[-1])
// br vector.body
//
// vector.body
// i = phi [0, vector.ph], [i+4, vector.body]
// v1 = phi [v_init, vector.ph], [v2, vector.body]
// v2 = a[i, i+1, i+2, i+3];
// v3 = vector(v1(3), v2(0, 1, 2))
// b[i, i+1, i+2, i+3] = v2 - v3
// br cond, vector.body, middle.block
//
// middle.block:
// x = v2(3)
// br scalar.ph
//
// scalar.ph:
// s_init = phi [x, middle.block], [a[-1], otherwise]
// br scalar.body
//
// After execution completes the vector loop, we extract the next value of
// the recurrence (x) to use as the initial value in the scalar loop.
// Get the original loop preheader and single loop latch.
auto *Preheader = OrigLoop->getLoopPreheader();
auto *Latch = OrigLoop->getLoopLatch();
// Get the initial and previous values of the scalar recurrence.
auto *ScalarInit = Phi->getIncomingValueForBlock(Preheader);
auto *Previous = Phi->getIncomingValueForBlock(Latch);
auto *IdxTy = Builder.getInt32Ty();
auto *EC = getElementCount(IdxTy, VF, Scalable);
auto *One = ConstantInt::get(IdxTy, 1);
auto *LastIdx = Builder.CreateBinOp(Instruction::Sub, EC, One);
// Create a vector from the initial value.
auto *VectorInit = ScalarInit;
if (VF > 1) {
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
VectorInit = Builder.CreateInsertElement(
UndefValue::get(VectorType::get(VectorInit->getType(), VF, Scalable)),
VectorInit, LastIdx, "vector.recur.init");
}
// We constructed a temporary phi node in the first phase of vectorization.
// This phi node will eventually be deleted.
auto &PhiParts = getVectorValue(Phi);
Builder.SetInsertPoint(cast<Instruction>(PhiParts[0]));
// Create a phi node for the new recurrence. The current value will either be
// the initial value inserted into a vector or loop-varying vector value.
auto *VecPhi = Builder.CreatePHI(VectorInit->getType(), 2, "vector.recur");
VecPhi->addIncoming(VectorInit, LoopVectorPreHeader);
// Get the vectorized previous value. We ensured the previous values was an
// instruction when detecting the recurrence.
auto &PreviousParts = getVectorValue(Previous);
// Set the insertion point to be after this instruction. We ensured the
// previous value dominated all uses of the phi when detecting the
// recurrence.
Builder.SetInsertPoint(
&*++BasicBlock::iterator(cast<Instruction>(PreviousParts[UF - 1])));
// We will construct a vector for the recurrence by combining the values for
// the current and previous iterations. This is the required shuffle mask.
auto *ShuffleMask = Builder.CreateSeriesVector({VF, Scalable},
LastIdx, One);
// The vector from which to take the initial value for the current iteration
// (actual or unrolled). Initially, this is the vector phi node.
Value *Incoming = VecPhi;
// Shuffle the current and previous vector and update the vector parts.
for (unsigned Part = 0; Part < UF; ++Part) {
auto *Shuffle =
VF > 1
? Builder.CreateShuffleVector(Incoming, PreviousParts[Part],
ShuffleMask)
: Incoming;
PhiParts[Part]->replaceAllUsesWith(Shuffle);
cast<Instruction>(PhiParts[Part])->eraseFromParent();
PhiParts[Part] = Shuffle;
Incoming = PreviousParts[Part];
}
// Fix the latch value of the new recurrence in the vector loop.
VecPhi->addIncoming(Incoming,
LI->getLoopFor(LoopVectorBody[0])->getLoopLatch());
// Extract the last vector element in the middle block. This will be the
// initial value for the recurrence when jumping to the scalar loop.
auto *Extract = Incoming;
if (VF > 1) {
Builder.SetInsertPoint(LoopMiddleBlock->getTerminator());
Extract = Builder.CreateExtractElement(Extract, LastIdx,
"vector.recur.extract");
}
// Fix the initial value of the original recurrence in the scalar loop.
Builder.SetInsertPoint(&*LoopScalarPreHeader->begin());
auto *Start = Builder.CreatePHI(Phi->getType(), 2, "scalar.recur.init");
for (auto *BB : predecessors(LoopScalarPreHeader)) {
auto *Incoming = BB == LoopMiddleBlock ? Extract : ScalarInit;
Start->addIncoming(Incoming, BB);
}
Phi->setIncomingValue(Phi->getBasicBlockIndex(LoopScalarPreHeader), Start);
Phi->setName("scalar.recur");
// Finally, fix users of the recurrence outside the loop. The users will need
// either the last value of the scalar recurrence or the last value of the
// vector recurrence we extracted in the middle block. Since the loop is in
// LCSSA form, we just need to find the phi node for the original scalar
// recurrence in the exit block, and then add an edge for the middle block.
for (auto &I : *LoopExitBlock) {
auto *LCSSAPhi = dyn_cast<PHINode>(&I);
if (!LCSSAPhi)
break;
if (LCSSAPhi->getIncomingValue(0) == Phi) {
LCSSAPhi->addIncoming(Extract, LoopMiddleBlock);
break;
}
}
}
void InnerLoopVectorizer::fixLCSSAPHIs() {
for (BasicBlock::iterator LEI = LoopExitBlock->begin(),
LEE = LoopExitBlock->end();
LEI != LEE; ++LEI) {
PHINode *LCSSAPhi = dyn_cast<PHINode>(LEI);
if (!LCSSAPhi)
break;
if (LCSSAPhi->getNumIncomingValues() == 1)
LCSSAPhi->addIncoming(UndefValue::get(LCSSAPhi->getType()),
LoopMiddleBlock);
}
}
InnerLoopVectorizer::VectorParts
InnerLoopVectorizer::createEdgeMask(BasicBlock *Src, BasicBlock *Dst) {
assert(std::find(pred_begin(Dst), pred_end(Dst), Src) != pred_end(Dst) &&
"Invalid edge");
// Look for cached value.
std::pair<BasicBlock *, BasicBlock *> Edge(Src, Dst);
EdgeMaskCache::iterator ECEntryIt = MaskCache.find(Edge);
if (ECEntryIt != MaskCache.end())
return ECEntryIt->second;
VectorParts SrcMask = createBlockInMask(Src);
// The terminator has to be a branch inst!
BranchInst *BI = dyn_cast<BranchInst>(Src->getTerminator());
assert(BI && "Unexpected terminator found");
if (BI->isConditional()) {
VectorParts EdgeMask = getVectorValue(BI->getCondition());
if (BI->getSuccessor(0) != Dst)
for (unsigned part = 0; part < UF; ++part)
EdgeMask[part] = Builder.CreateNot(EdgeMask[part]);
for (unsigned part = 0; part < UF; ++part)
EdgeMask[part] = Builder.CreateAnd(EdgeMask[part], SrcMask[part]);
MaskCache[Edge] = EdgeMask;
return EdgeMask;
}
MaskCache[Edge] = SrcMask;
return SrcMask;
}
InnerLoopVectorizer::VectorParts
InnerLoopVectorizer::createBlockInMask(BasicBlock *BB) {
assert(OrigLoop->contains(BB) && "Block is not a part of a loop");
// Loop incoming mask is all-one.
if (OrigLoop->getHeader() == BB) {
Value *C = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 1);
return getVectorValue(C);
}
// This is the block mask. We OR all incoming edges, and with zero.
Value *Zero = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 0);
VectorParts BlockMask = getVectorValue(Zero);
// For each pred:
for (pred_iterator it = pred_begin(BB), e = pred_end(BB); it != e; ++it) {
VectorParts EM = createEdgeMask(*it, BB);
for (unsigned part = 0; part < UF; ++part)
BlockMask[part] = Builder.CreateOr(BlockMask[part], EM[part]);
}
return BlockMask;
}
void InnerLoopVectorizer::widenPHIInstruction(
Instruction *PN, InnerLoopVectorizer::VectorParts &Entry, unsigned UF,
unsigned VF, PhiVector *PV) {
PHINode *P = cast<PHINode>(PN);
// Handle recurrences.
if (Legal->isReductionVariable(P) || Legal->isFirstOrderRecurrence(P)) {
for (unsigned part = 0; part < UF; ++part) {
// This is phase one of vectorizing PHIs.
RecurrenceDescriptor RdxDesc = (*Legal->getReductionVars())[P];
Type *VecTy = (VF == 1 || RdxDesc.isOrdered())
? PN->getType()
: VectorType::get(PN->getType(), VF, Scalable);
Entry[part] = PHINode::Create(VecTy, 2, "vec.phi",
&*LoopVectorBody[0]->getFirstInsertionPt());
}
PV->push_back(P);
return;
}
setDebugLocFromInst(Builder, P);
// Check for PHI nodes that are lowered to vector selects.
if (P->getParent() != OrigLoop->getHeader()) {
// We know that all PHIs in non-header blocks are converted into
// selects, so we don't have to worry about the insertion order and we
// can just use the builder.
// At this point we generate the predication tree. There may be
// duplications since this is a simple recursive scan, but future
// optimizations will clean it up.
unsigned NumIncoming = P->getNumIncomingValues();
// If the value is an exit value of a strictly ordered reduction,
// skip this PHI node since the inputs to the reduction, as well as
// the reduction itself, will already have been predicated.
for (auto &Reduction : *Legal->getReductionVars()) {
RecurrenceDescriptor DS = Reduction.second;
auto LoopExitInstr = DS.getLoopExitInstr();
if (LoopExitInstr == PN && DS.isOrdered()) {
Value *V = DS.getUnsafeAlgebraInst();
for (unsigned part = 0; part < UF; ++part)
Entry[part] = getVectorValue(V)[part];
return;
}
}
// Generate a sequence of selects of the form:
// SELECT(Mask3, In3,
// SELECT(Mask2, In2,
// ( ...)))
for (unsigned In = 0; In < NumIncoming; In++) {
VectorParts Cond =
createEdgeMask(P->getIncomingBlock(In), P->getParent());
VectorParts &In0 = getVectorValue(P->getIncomingValue(In));
for (unsigned part = 0; part < UF; ++part) {
// We might have single edge PHIs (blocks) - use an identity
// 'select' for the first PHI operand.
if (In == 0)
Entry[part] = Builder.CreateSelect(Cond[part], In0[part], In0[part]);
else
// Select between the current value and the previous incoming edge
// based on the incoming mask.
Entry[part] = Builder.CreateSelect(Cond[part], In0[part], Entry[part],
"predphi");
}
}
return;
}
// This PHINode must be an induction variable.
// Make sure that we know about it.
assert(Legal->getInductionVars()->count(P) && "Not an induction variable");
InductionDescriptor II = Legal->getInductionVars()->lookup(P);
const DataLayout &DL = OrigLoop->getHeader()->getModule()->getDataLayout();
// FIXME: The newly created binary instructions should contain nsw/nuw flags,
// which can be found from the original scalar operations.
switch (II.getKind()) {
case InductionDescriptor::IK_NoInduction:
llvm_unreachable("Unknown induction");
case InductionDescriptor::IK_IntInduction: {
Type *PhiTy = P->getType();
assert(P->getType() == II.getStartValue()->getType() && "Types must match");
// Handle other induction variables that are now based on the
// canonical one.
Value *V = Induction;
if (P != OldInduction || VF == 1) {
// Handle other induction variables that are now based on the
// canonical one.
if (P != OldInduction) {
V = Builder.CreateSExtOrTrunc(Induction, PhiTy);
V = II.transform(Builder, V, PSE.getSE(), DL);
V->setName("offset.idx");
}
Value *Broadcasted = getBroadcastInstrs(V);
Value *NumEls = getElementCount(PhiTy, VF, Scalable, PhiTy);
// After broadcasting the induction variable we need to make the vector
// consecutive by adding 0, 1, 2, etc.
for (unsigned part = 0; part < UF; ++part) {
Value *Part = ConstantInt::get(PhiTy, part);
Value *StartIdx = Builder.CreateMul(NumEls, Part);
Entry[part] = getStepVector(Broadcasted, StartIdx, II.getStep());
}
} else {
// Instead of re-creating the vector IV by splatting the scalar IV
// in each iteration, we can make a new independent vector IV.
widenInductionVariable(II, Entry);
}
return;
}
case InductionDescriptor::IK_FpInduction: {
Type *PhiTy = P->getType();
Value *V = Builder.CreateCast(Instruction::SIToFP, Induction, P->getType());
V = II.transform(Builder, V, PSE.getSE(), DL);
V->setName("fp.offset.idx");
Value *Broadcasted = getBroadcastInstrs(V);
Value *NumEls = getElementCount(PhiTy, VF, Scalable);
for (unsigned part = 0; part < UF; ++part) {
Value *Part = Builder.getInt32(part);
Value *StartIdx = Builder.CreateMul(NumEls, Part);
auto *StepVal = cast<SCEVUnknown>(II.getStep())->getValue();
Entry[part] = getStepVector(Broadcasted, StartIdx, StepVal,
II.getInductionOpcode());
}
return;
}
case InductionDescriptor::IK_PtrInduction: {
// Handle the pointer induction variable case.
assert(P->getType()->isPointerTy() && "Unexpected type.");
// This is the normalized GEP that starts counting at zero.
Value *PtrInd = Induction;
PtrInd = Builder.CreateSExtOrTrunc(PtrInd, II.getStep()->getType());
if (!isScalable()) {
// This is the vector of results. Notice that we don't generate
// vector geps because scalar geps result in better code.
for (unsigned part = 0; part < UF; ++part) {
if (VF == 1) {
int EltIndex = part;
Constant *Idx = ConstantInt::get(PtrInd->getType(),EltIndex);
Value *GlobalIdx = Builder.CreateAdd(PtrInd, Idx);
Value *SclrGep = II.transform(Builder, GlobalIdx, PSE.getSE(), DL);
SclrGep->setName("next.gep");
Entry[part] = SclrGep;
continue;
}
Value *VecVal = UndefValue::get(VectorType::get(P->getType(), VF));
for (unsigned int i = 0; i < VF; ++i) {
int EltIndex = i + part * VF;
Constant *Idx = ConstantInt::get(PtrInd->getType(),EltIndex);
Value *GlobalIdx = Builder.CreateAdd(PtrInd, Idx);
Value *SclrGep = II.transform(Builder, GlobalIdx, PSE.getSE(), DL);
SclrGep->setName("next.gep");
VecVal = Builder.CreateInsertElement(VecVal, SclrGep,
Builder.getInt32(i),
"insert.gep");
}
Entry[part] = VecVal;
}
} else {
Type *PhiTy = PtrInd->getType();
Value *NumEls = getElementCount(P->getType(), VF, Scalable, PhiTy);
Value *StepValue;
ScalarEvolution *SE = PSE.getSE();
const DataLayout &DL = PN->getModule()->getDataLayout();
SCEVExpander Expander(*SE, DL, "seriesgep");
if (Legal->getInductionVars()->count(P)) {
const SCEV *Step = Legal->getInductionVars()->lookup(P).getStep();
StepValue = Expander.expandCodeFor(Step, Step->getType(),
&*Builder.GetInsertPoint());
} else {
auto *SAR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(PN));
assert(SAR && SAR->isAffine() && "Pointer induction not loop affine");
// Expand step and start value (the latter in preheader)
const SCEV *StepRec = SAR->getStepRecurrence(*SE);
StepValue = Expander.expandCodeFor(StepRec, StepRec->getType(),
&*Builder.GetInsertPoint());
// Normalize step to be in #elements, not bytes
Type *ElemTy = PN->getType()->getPointerElementType();
Value *Tmp = ConstantInt::get(StepValue->getType(),
DL.getTypeAllocSize(ElemTy));
StepValue = Builder.CreateSDiv(StepValue, Tmp);
}
for (unsigned part = 0; part < UF; ++part) {
Value *Part = ConstantInt::get(PhiTy, part);
Value *Idx = Builder.CreateMul(NumEls, Part);
Value *GlobalIdx = Builder.CreateAdd(PtrInd, Idx);
Value *SclrGep = II.transform(Builder, GlobalIdx, SE, DL);
SclrGep->setName("next.gep");
Value *Offs = Builder.CreateSeriesVector({VF,Scalable},
ConstantInt::get(StepValue->getType(), 0), StepValue);
Entry[part] = Builder.CreateGEP(SclrGep, Offs);
Entry[part]->setName("vector.gep");
}
}
return;
}
}
}
// Vectorize GEP as arithmetic instructions.
//
// This is required when a given GEP is not used for a load/store operation,
// but rather to implement pointer arithmetic. In this case, the pointer may
// be a vector of pointers (e.g. resulting from a load).
//
// This function makes a ptrtoint->arith->inttoptr transformation.
//
// extern char * reg_names[];
// void foo(void) {
// for (int i = 0; i < K; i++)
// reg_names[i]--;
// }
//
// %1 = getelementptr inbounds [0 x i8*]* @reg_names, i64 0, i64 %0
// %2 = bitcast i8** %1 to <n x 8 x i8*>*
// %wide.load = load <n x 8 x i8*>* %2, align 8, !tbaa !1
// %3 = ptrtoint <n x 8 x i8*> %wide.load to <n x 8 x i64>
// %4 = add <n x 8 x i64> %3, seriesvector (i64 -1, i64 0)
// %5 = inttoptr <n x 8 x i64> %4 to <n x 8 x i8*>
// %6 = bitcast i8** %1 to <n x 8 x i8*>*
// store <n x 8 x i8*> %5, <n x 8 x i8*>* %6, align 8, !tbaa !1
void InnerLoopVectorizer::vectorizeArithmeticGEP(Instruction *Instr) {
assert(isa<GetElementPtrInst>(Instr) && "Instr is not a GEP");
GetElementPtrInst *GEP = static_cast<GetElementPtrInst *>(Instr);
// Used types for inttoptr/ptrtoint transform
Type *OrigPtrType = GEP->getType();
const DataLayout &DL = GEP->getModule()->getDataLayout();
Type *IntPtrType = DL.getIntPtrType(GEP->getType());
// Constant and Variable elements are kept separate to allow IRBuilder
// to fold the constant before widening it to a vector.
VectorParts &Base = getVectorValue(GEP->getPointerOperand());
VectorParts &Res = WidenMap.get(Instr);
for (unsigned Part = 0; Part < UF; ++Part) {
// Pointer To Int (pointer operand)
Res[Part] = Builder.CreatePtrToInt(
Base[Part], VectorType::get(IntPtrType, VF, Scalable));
// Collect constants and split up the GEP expression into an arithmetic one.
Value *Cst = ConstantInt::get(IntPtrType, 0, false);
gep_type_iterator GTI = gep_type_begin(*GEP);
for (unsigned I = 1, E = GEP->getNumOperands(); I != E; ++I, ++GTI) {
// V is still scalar
Value *V = GEP->getOperand(I);
if (StructType *STy = GTI.getStructTypeOrNull()) {
// Struct type, get field offset in bytes. Result is always a constant.
assert(isa<ConstantInt>(V) && "Field offset must be constant");
ConstantInt *CI = static_cast<ConstantInt *>(V);
unsigned ByteOffset =
DL.getStructLayout(STy)->getElementOffset(CI->getLimitedValue());
V = ConstantInt::get(IntPtrType, ByteOffset, false);
} else {
// First transform index to pointer-type
if (V->getType() != IntPtrType)
V = Builder.CreateIntCast(V, IntPtrType, true, "idxprom");
Value *TypeAllocSize = ConstantInt::get(
V->getType(), DL.getTypeAllocSize(GTI.getIndexedType()), true);
// Only widen non-constant offsets
if (isa<Constant>(V))
V = Builder.CreateMul(V, TypeAllocSize);
else
V = Builder.CreateMul(getVectorValue(V)[Part],
getVectorValue(TypeAllocSize)[Part]);
}
if (isa<Constant>(V))
Cst = Builder.CreateAdd(Cst, V);
else
Res[Part] = Builder.CreateAdd(Res[Part], V);
}
// Add constant part and create final conversion to original type
Res[Part] = Builder.CreateAdd(Res[Part], getVectorValue(Cst)[Part]);
Res[Part] = Builder.CreateIntToPtr(
Res[Part], VectorType::get(OrigPtrType, VF, Scalable));
}
}
void InnerLoopVectorizer::patchLatchBranch(BranchInst *Br) {
assert(UsePredication && "Expect predicate to drive loop termination.");
assert(Br->getParent() == OrigLoop->getLoopLatch() &&
"Non-latch branch cannot be patched");
BasicBlock *LastBB = LoopVectorBody.back();
// TODO: Shouldn't need to create new step + compare, just work with
// existing compare? does propff do what we want? better to expose
// partitioning instrs directly?
// For now, we've just copied the original createEmptyLoopWithPredication
// logic of generating a predicate solely from the (known) trip count.
// When using predication the number of elements processed per iteration
// becomes a runtime quantity. However, index.next is calculated making the
// assumption that a whole vector's worth of elements are processed, which
// today is true for all but the last iteration. This means index.next can
// potentially be larger than that within the original loop, which prevents
// the propagation of the original's wrapping knowldge.
//
// Instead we use scalar evolution to determine the wrapping behaviour of the
// vector loop's index.next so later passes can optimise our control flow.
// TODO: Certain loops will force the requirement that index.next be accurate
// when exiting the loop, at which point an 'active element count' will be
// used. However, it seems inefficient to force this requirement for loops
// that don't need it.
ScalarEvolution *SE = PSE.getSE();
const SCEV *IdxEndSCEV = SE->getSCEV(IdxEnd);
APInt MaxIdxEnd = SE->getUnsignedRange(IdxEndSCEV).getUpper() - 1;
const SCEV *StepSCEV = SE->getSCEV(InductionStep);
APInt MaxStep = SE->getUnsignedRange(StepSCEV).getUpper();
bool Overflow;
APInt T1 = MaxIdxEnd.sadd_ov(MaxStep, Overflow);
if (!Overflow)
T1.sadd_ov(MaxStep, Overflow);
bool NSW = !Overflow;
APInt T2 = MaxIdxEnd.uadd_ov(MaxStep, Overflow);
if (!Overflow)
T2.uadd_ov(MaxStep, Overflow);
bool NUW = !Overflow;
Value *One = ConstantInt::get(Legal->getWidestInductionType(), 1);
Type *IdxTy = Legal->getWidestInductionType();
Value *TV = UndefValue::get(VectorType::get(IdxTy, VF, Scalable));
Value *RuntimeVF = Builder.CreateElementCount(IdxTy, TV);
// Propagate the predicates along the interleaved vector instructions.
// For an UF = 4, see example below, where each line represents one iteration
// of the unrolled loop, 'c' stands for current predicate and 'n' for next
// predicate.
// In each iteration, the first next predicate (n0) is propagated from last
// iteration current predicate (c3).
// [c0][c1][c2][c3][n0][n1][n2][n3]
// [c0][c1][c2][c3][n0][n1][n2][n3]
// [c0][c1][c2][c3][n0][n1][n2][n3]
Value *PropValue = Predicate[UF-1];
Value *NextIdx = Builder.CreateAdd(Induction, InductionStep, "index.next",
NUW, NSW);
for (unsigned i = 0; i < UF; ++i) {
Value *Step = Builder.CreateMul(RuntimeVF, ConstantInt::get(IdxTy, i));
Value *Idx = Builder.CreateAdd(NextIdx, Step, "", NUW, NSW);
// Create the next predicate taking integer overflow into account.
Value *NextPred = Builder.CreateSeriesVector({VF,Scalable}, Idx, One);
NextPred = Builder.CreateICmpULT(NextPred, IdxEndV);
PropValue = Builder.CreatePropFF(PropValue, NextPred, "predicate.next");
Predicate[i]->addIncoming(PropValue, LastBB);
}
// An active first element means we have more work to do.
PHINode *FirstPredPhi = Predicate.front();
Value *FinalTest = FirstPredPhi->getIncomingValueForBlock(LastBB);
// Test for first lane active.
Value *Done = Builder.CreateExtractElement(FinalTest, Builder.getInt64(0));
Induction->addIncoming(NextIdx, LoopVectorBody.back());
LatchBranch->setCondition(Done);
// ----------------------------------------------------------------------
// Generate an llvm.assume() intrinsic about the bounds of this loopvar
// if the chosen Index value replaces induction variables with smaller
// type and/or range. This can be used in InstCombine for better folding
// of some cases.
// ----------------------------------------------------------------------
// Get the range of the induction value.
auto IndTy = cast<IntegerType>(Induction->getType());
APInt MinRange = MaxIdxEnd;
// Find a loop variable with the same start/step value
// and reduce the range if possible.
LoopVectorizationLegality::InductionList::iterator I, E;
LoopVectorizationLegality::InductionList *List = Legal->getInductionVars();
for (I = List->begin(), E = List->end(); I != E; ++I) {
// Ignore FP inductions.
if (!I->first->getType()->isIntegerTy())
continue;
// Check it is a non-negative, non-wrapping AddRec.
auto *Phi = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(I->first));
if (!Phi)
continue;
// Must have same step value.
if (!Phi->getStepRecurrence(*SE)->isOne())
continue;
// If range is smaller, reduce.
APInt RRange = SE->getUnsignedRange(Phi).getSetSize();
if (MinRange.getBitWidth() > RRange.getBitWidth())
RRange = RRange.zext(MinRange.getBitWidth());
else if (MinRange.getBitWidth() < RRange.getBitWidth())
MinRange = MinRange.zext(RRange.getBitWidth());
if (RRange.ult(MinRange))
MinRange = RRange;
}
ConstantInt *MaxInd = ConstantInt::get(IndTy, MinRange.getLimitedValue());
if (MaxInd->isMaxValue(false /* unsigned */))
return;
// Create the assume intrinsic in the preheader (llvm.assume must
// dominate use in order to be effective in InstCombine)
BasicBlock::iterator IP = Builder.GetInsertPoint();
Builder.SetInsertPoint(IP->getParent()->getFirstNonPHI());
// Induction < minrange.Upper
CallInst *Assumption = Builder.CreateAssumption(
Builder.CreateICmpULT(Induction, MaxInd));
AC->registerAssumption(Assumption);
// Restore insertion point
Builder.SetInsertPoint(IP->getParent(), IP);
}
bool
InnerLoopVectorizer::testHorizontalReductionExitInst(Instruction *I,
RecurrenceDescriptor &RD) {
auto Redux = Legal->getReductionVars();
bool Found = false;
for (auto Red : *Redux) {
auto RedDesc = Red.second;
if (!RedDesc.isOrdered())
continue;
if (RedDesc.getLoopExitInstr() == I) {
Found = true;
RD = RedDesc;
break;
}
// Test if this is a PHI with an input from a horizontal ordered reduction.
auto P = dyn_cast<PHINode>(RedDesc.getLoopExitInstr());
if (P && P->getNumIncomingValues() == 2 &&
((P->getIncomingValue(0) == I) || (P->getIncomingValue(1) == I))) {
Found = true;
RD = RedDesc;
break;
}
}
if (!Found)
return false;
DEBUG(dbgs() << "LV: found an ordered horizontal reduction: ";
I->print(dbgs());
dbgs()<< "\n");
return true;
}
void InnerLoopVectorizer::vectorizeBlockInLoop(BasicBlock *BB, PhiVector *PV) {
// For each instruction in the old loop.
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
VectorParts &Entry = WidenMap.get(&*it);
switch (it->getOpcode()) {
case Instruction::Br:
if (UsePredication && BB == OrigLoop->getLoopLatch())
patchLatchBranch(cast<BranchInst>(it));
continue;
case Instruction::PHI: {
// Vectorize PHINodes.
widenPHIInstruction(&*it, Entry, UF, VF, PV);
continue;
} // End of PHI.
case Instruction::FAdd: {
// Just widen binops.
BinaryOperator *BinOp = dyn_cast<BinaryOperator>(it);
setDebugLocFromInst(Builder, BinOp);
VectorParts &A = getVectorValue(it->getOperand(0));
VectorParts &B = getVectorValue(it->getOperand(1));
// Use this vector value for all users of the original instruction.
RecurrenceDescriptor RD;
const bool isHorizontalReduction =
testHorizontalReductionExitInst(&*it, RD);
VectorParts Mask = createBlockInMask(it->getParent());
for (unsigned Part = 0; Part < UF; ++Part) {
Value *V = nullptr;
if (!isHorizontalReduction || VF == 1) {
V = Builder.CreateBinOp(BinOp->getOpcode(), A[Part], B[Part]);
if (BinaryOperator *VecOp = dyn_cast<BinaryOperator>(V))
VecOp->copyIRFlags(BinOp);
} else {
auto X = A[Part];
auto Y = B[Part];
auto XTy = X->getType();
auto YTy = Y->getType();
if (YTy->isVectorTy() && !XTy->isVectorTy()) {
if (Part > 0)
X = Entry[Part-1];
auto P = Builder.CreateAnd(Mask[Part], Predicate[Part]);
V = createOrderedReduction(Builder, RD, Y, X, P);
}
if (XTy->isVectorTy() && !YTy->isVectorTy()) {
if (Part > 0)
Y = Entry[Part-1];
auto P = Builder.CreateAnd(Mask[Part], Predicate[Part]);
V = createOrderedReduction(Builder, RD, X, Y, P);
}
assert(V && "cannot find the reduction intrinsic");
}
Entry[Part] = V;
}
addMetadata(Entry, &*it);
break;
}
case Instruction::Add:
case Instruction::Sub:
case Instruction::FSub:
case Instruction::Mul:
case Instruction::FMul:
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::FDiv:
case Instruction::URem:
case Instruction::SRem:
case Instruction::FRem:
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
case Instruction::And:
case Instruction::Or:
case Instruction::Xor: {
// Just widen binops.
BinaryOperator *BinOp = dyn_cast<BinaryOperator>(it);
setDebugLocFromInst(Builder, BinOp);
VectorParts &A = getVectorValue(it->getOperand(0));
VectorParts &B = getVectorValue(it->getOperand(1));
// Use this vector value for all users of the original instruction.
for (unsigned Part = 0; Part < UF; ++Part) {
Value *V = Builder.CreateBinOp(BinOp->getOpcode(), A[Part], B[Part]);
if (BinaryOperator *VecOp = dyn_cast<BinaryOperator>(V))
VecOp->copyIRFlags(BinOp);
Entry[Part] = V;
}
addMetadata(Entry, &*it);
break;
}
case Instruction::Select: {
// Widen selects.
// If the selector is loop invariant we can create a select
// instruction with a scalar condition. Otherwise, use vector-select.
auto *SE = PSE.getSE();
bool InvariantCond =
SE->isLoopInvariant(PSE.getSCEV(it->getOperand(0)), OrigLoop);
setDebugLocFromInst(Builder, &*it);
// The condition can be loop invariant but still defined inside the
// loop. This means that we can't just use the original 'cond' value.
// We have to take the 'vectorized' value and pick the first lane.
// Instcombine will make this a no-op.
VectorParts &Cond = getVectorValue(it->getOperand(0));
VectorParts &Op0 = getVectorValue(it->getOperand(1));
VectorParts &Op1 = getVectorValue(it->getOperand(2));
Value *ScalarCond =
(VF == 1)
? Cond[0]
: Builder.CreateExtractElement(Cond[0], Builder.getInt32(0));
for (unsigned Part = 0; Part < UF; ++Part) {
Entry[Part] = Builder.CreateSelect(
InvariantCond ? ScalarCond : Cond[Part], Op0[Part], Op1[Part]);
}
addMetadata(Entry, &*it);
break;
}
case Instruction::ICmp:
case Instruction::FCmp: {
// Widen compares. Generate vector compares.
bool FCmp = (it->getOpcode() == Instruction::FCmp);
CmpInst *Cmp = dyn_cast<CmpInst>(it);
setDebugLocFromInst(Builder, &*it);
VectorParts &A = getVectorValue(it->getOperand(0));
VectorParts &B = getVectorValue(it->getOperand(1));
for (unsigned Part = 0; Part < UF; ++Part) {
Value *C = nullptr;
if (FCmp) {
C = Builder.CreateFCmp(Cmp->getPredicate(), A[Part], B[Part]);
cast<FCmpInst>(C)->copyFastMathFlags(&*it);
} else {
C = Builder.CreateICmp(Cmp->getPredicate(), A[Part], B[Part]);
}
Entry[Part] = C;
}
addMetadata(Entry, &*it);
break;
}
case Instruction::Store:
case Instruction::Load:
vectorizeMemoryInstruction(&*it);
break;
case Instruction::ZExt:
case Instruction::SExt:
case Instruction::FPToUI:
case Instruction::FPToSI:
case Instruction::FPExt:
case Instruction::PtrToInt:
case Instruction::IntToPtr:
case Instruction::SIToFP:
case Instruction::UIToFP:
case Instruction::Trunc:
case Instruction::FPTrunc:
case Instruction::BitCast: {
CastInst *CI = dyn_cast<CastInst>(it);
setDebugLocFromInst(Builder, &*it);
/// Optimize the special case where the source is a constant integer
/// induction variable. Notice that we can only optimize the 'trunc' case
/// because: a. FP conversions lose precision, b. sext/zext may wrap,
/// c. other casts depend on pointer size.
if (CI->getOperand(0) == OldInduction &&
it->getOpcode() == Instruction::Trunc) {
InductionDescriptor II =
Legal->getInductionVars()->lookup(OldInduction);
if (auto StepValue = II.getConstIntStepValue()) {
IntegerType *TruncType = cast<IntegerType>(CI->getType());
if (VF == 1) {
StepValue =
ConstantInt::getSigned(TruncType, StepValue->getSExtValue());
Value *ScalarCast =
Builder.CreateCast(CI->getOpcode(), Induction, CI->getType());
Value *Broadcasted = getBroadcastInstrs(ScalarCast);
Type* ElemTy = Broadcasted->getType()->getScalarType();
Value* NumEls = getElementCount(ElemTy, VF, Scalable, ElemTy);
for (unsigned Part = 0; Part < UF; ++Part) {
Value *Start =
Builder.CreateMul(NumEls, ConstantInt::get(ElemTy, Part));
Entry[Part] = getStepVector(Broadcasted, Start, StepValue);
}
} else {
// Truncating a vector induction variable on each iteration
// may be expensive. Instead, truncate the initial value, and create
// a new, truncated, vector IV based on that.
widenInductionVariable(II, Entry, TruncType);
}
addMetadata(Entry, &*it);
break;
}
}
/// Vectorize casts.
Type *DestTy =
(VF == 1) ? CI->getType() :
VectorType::get(CI->getType(), VF, Scalable);
VectorParts &A = getVectorValue(it->getOperand(0));
for (unsigned Part = 0; Part < UF; ++Part)
Entry[Part] = Builder.CreateCast(CI->getOpcode(), A[Part], DestTy);
addMetadata(Entry, &*it);
break;
}
case Instruction::Call: {
if (auto MSI = dyn_cast<MemSetInst>(it)) {
vectorizeMemsetInstruction(MSI);
break;
}
// Ignore dbg intrinsics.
if (isa<DbgInfoIntrinsic>(it))
break;
setDebugLocFromInst(Builder, &*it);
Module *M = BB->getParent()->getParent();
CallInst *CI = cast<CallInst>(it);
StringRef FnName = CI->getCalledFunction()->getName();
Function *F = CI->getCalledFunction();
Type *RetTy = ToVectorTy(CI->getType(), VF, Scalable);
Intrinsic::ID ID =
getVectorIntrinsicIDForCall(CI, TLI, UsePredication && VF > 1);
if (ID &&
(ID == Intrinsic::assume || ID == Intrinsic::lifetime_end ||
ID == Intrinsic::lifetime_start)) {
if (isScalable() &&
OrigLoop->isLoopInvariant(it->getOperand(0)) &&
OrigLoop->isLoopInvariant(it->getOperand(1)))
Builder.Insert(it->clone());
else
scalarizeInstruction(&*it);
break;
}
// The flag shows whether we use Intrinsic or a usual Call for vectorized
// version of the instruction.
// Is it beneficial to perform intrinsic call compared to lib call?
bool NeedToScalarize;
unsigned CallCost = getVectorCallCost(CI, {VF, 1, !isScalable()}, *TTI,
TLI, *Legal, NeedToScalarize);
NeedToScalarize = NeedToScalarize && (!isScalable());
bool UseVectorIntrinsic =
ID && getVectorIntrinsicCost(CI, VF, *TTI, TLI) <= CallCost;
if (!UseVectorIntrinsic && NeedToScalarize) {
scalarizeInstruction(&*it);
break;
}
const auto IsThereAMaskParam = isMaskedVectorIntrinsic(ID);
const bool IsPredicated = IsThereAMaskParam.first ;
const unsigned MaskPosition = IsThereAMaskParam.second ;
const bool CallNeedsPredication = IsPredicated ||
(UsePredication && TLI->isFunctionVectorizable(FnName));
for (unsigned Part = 0; Part < UF; ++Part) {
SmallVector<Value *, 4> Args;
for (unsigned i = 0, ie = CI->getNumArgOperands(); i != ie; ++i) {
Value *Arg = CI->getArgOperand(i);
// Some intrinsics have a scalar argument - don't replace it with a
// vector.
if (!UseVectorIntrinsic || !hasVectorInstrinsicScalarOpd(ID, i)) {
VectorParts &VectorArg = getVectorValue(CI->getArgOperand(i));
Arg = VectorArg[Part];
}
Args.push_back(Arg);
}
if (CallNeedsPredication) {
// If the intrinsic or function is maskable, then we need to pass in
// the loop predicate.
const SmallVectorImpl<Value *>::iterator Insert = UseVectorIntrinsic ?
Args.begin() + MaskPosition : Args.end();
Args.insert(Insert, Predicate[Part]);
}
Function *VectorF;
if (UseVectorIntrinsic) {
// Use vector version of the intrinsic.
Type *TysForDecl[] = {CI->getType()};
if (VF > 1)
TysForDecl[0] = VectorType::get(CI->getType()->getScalarType(),
VF, Scalable);
VectorF = Intrinsic::getDeclaration(M, ID, TysForDecl);
} else {
SmallVector<Type *, 4> Tys;
for (unsigned i = 0, ie = CI->getNumArgOperands(); i != ie; ++i) {
Value *Arg = CI->getArgOperand(i);
// Check if the argument `x` is a pointer marked by an
// OpenMP clause `linear(x:1)`.
if (Arg->getType()->isPointerTy() &&
(Legal->isConsecutivePtr(Arg) == 1) &&
isa<VectorType>(Args[i]->getType())) {
DEBUG(dbgs() << "LV: vectorizing " << *Arg
<< " as a linear pointer with step 1");
Args[i] =
Builder.CreateExtractElement(Args[i], Builder.getInt32(0));
Tys.push_back(Arg->getType());
} else
Tys.push_back(ToVectorTy(Arg->getType(), VF, Scalable));
}
if (CallNeedsPredication) {
// If the intrinsic or function is maskable, then we need to pass in
// the loop predicate type in the correct place of the signature.
const SmallVectorImpl<Type *>::iterator Insert =
UseVectorIntrinsic ? Tys.begin() + MaskPosition : Tys.end();
Tys.insert(Insert, Predicate[0]->getType());
}
// Use vector version of the library call.
FunctionType *FTy = FunctionType::get(RetTy, Tys, false);
DEBUG(dbgs() << "SVE LV: Looking for a signature" << *FTy << "\n");
const std::string VFnName = TLI->getVectorizedFunction(FnName, VF, FTy);
assert(!VFnName.empty() && "Vector function name is empty.");
VectorF = M->getFunction(VFnName);
if (!VectorF) {
// Generate a declaration
VectorF =
Function::Create(FTy, Function::ExternalLinkage, VFnName, M);
VectorF->copyAttributesFrom(F);
}
}
assert(VectorF && "Can't create vector function.");
SmallVector<OperandBundleDef, 1> OpBundles;
CI->getOperandBundlesAsDefs(OpBundles);
CallInst *V = Builder.CreateCall(VectorF, Args, OpBundles);
if (isa<FPMathOperator>(V))
V->copyFastMathFlags(CI);
Entry[Part] = V;
}
addMetadata(Entry, &*it);
break;
}
case Instruction::GetElementPtr:
vectorizeGEPInstruction(&*it);
break;
default:
// All other instructions are unsupported. Scalarize them.
scalarizeInstruction(&*it);
break;
} // end of switch.
} // end of for_each instr.
}
void InnerLoopVectorizer::updateAnalysis() {
// Forget the original basic block.
PSE.getSE()->forgetLoop(OrigLoop);
// Update the dominator tree information.
assert(DT->properlyDominates(LoopBypassBlocks.front(), LoopExitBlock) &&
"Entry does not dominate exit.");
/*
for (unsigned I = 1, E = LoopBypassBlocks.size(); I != E; ++I)
DT->addNewBlock(LoopBypassBlocks[I], LoopBypassBlocks[I-1]);
DT->addNewBlock(LoopVectorPreHeader, LoopBypassBlocks.back());
*/
// Add dominator for first vector body block.
DT->addNewBlock(LoopVectorBody[0], LoopVectorPreHeader);
for (const auto &Edge : VecBodyDomEdges)
DT->addNewBlock(Edge.second, Edge.first);
DT->addNewBlock(LoopMiddleBlock, LoopVectorBody.back());
DT->addNewBlock(LoopScalarPreHeader, LoopBypassBlocks[0]);
DT->changeImmediateDominator(LoopScalarBody, LoopScalarPreHeader);
DT->changeImmediateDominator(LoopExitBlock, LoopBypassBlocks[0]);
DEBUG(DT->verifyDomTree());
}
/// \brief Check whether it is safe to if-convert this phi node.
///
/// Phi nodes with constant expressions that can trap are not safe to if
/// convert.
static bool canIfConvertPHINodes(BasicBlock *BB) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
PHINode *Phi = dyn_cast<PHINode>(I);
if (!Phi)
return true;
for (unsigned p = 0, e = Phi->getNumIncomingValues(); p != e; ++p)
if (Constant *C = dyn_cast<Constant>(Phi->getIncomingValue(p)))
if (C->canTrap())
return false;
}
return true;
}
bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
bool CanIfConvert = true;
if (!EnableIfConversion) {
ORE->emit(createMissedAnalysis("IfConversionDisabled")
<< "if-conversion is disabled");
DEBUG(dbgs() << "LV: Not vectorizing - if-conversion is disabled.\n");
CanIfConvert = false;
NODEBUG_EARLY_BAILOUT();
}
assert(TheLoop->getNumBlocks() > 1 && "Single block loops are vectorizable");
// A list of pointers that we can safely read and write to.
SmallPtrSet<Value *, 8> SafePointes;
// Collect safe addresses.
for (BasicBlock *BB : TheLoop->blocks()) {
if (blockNeedsPredication(BB))
continue;
for (Instruction &I : *BB)
if (auto *Ptr = getPointerOperand(&I))
SafePointes.insert(Ptr);
}
// Collect the blocks that need predication.
BasicBlock *Header = TheLoop->getHeader();
for (BasicBlock *BB : TheLoop->blocks()) {
// We don't support switch statements inside loops.
if (!isa<BranchInst>(BB->getTerminator())) {
ORE->emit(createMissedAnalysis("LoopContainsSwitch", BB->getTerminator())
<< "loop contains a switch statement");
DEBUG(dbgs() <<
"LV: Not vectorizing - loop contains a switch statement.\n");
CanIfConvert = false;
NODEBUG_EARLY_BAILOUT();
}
// We must be able to predicate all blocks that need to be predicated.
BasicBlock *PredB = BB->getSinglePredecessor();
DebugLoc CmpLoc = DebugLoc();
if (PredB && PredB->getTerminator())
CmpLoc = PredB->getTerminator()->getDebugLoc();
if (blockNeedsPredication(BB)) {
if (!blockCanBePredicated(BB, SafePointes)) {
auto R = createMissedAnalysis("NoCFGForSelect");
R << "control flow cannot be substituted for a select";
if (auto *PredB = BB->getSinglePredecessor())
R << ore::setExtraArgs() << ore::NV("Cmp", PredB->getTerminator());
ORE->emit(R);
DEBUG(dbgs() <<
"LV: Not vectorizing - cannot predicate all blocks for if-conversion.\n");
CanIfConvert = false;
NODEBUG_EARLY_BAILOUT();
}
} else if (BB != Header && !canIfConvertPHINodes(BB)) {
auto R = createMissedAnalysis("NoCFGForSelect");
R << "control flow cannot be substituted for a select";
if (auto *PredB = BB->getSinglePredecessor())
R << ore::setExtraArgs() << ore::NV("Cmp", PredB->getTerminator());
ORE->emit(R);
DEBUG(dbgs() <<
"LV: Not vectorizing - phi nodes cannot be if converted.\n");
CanIfConvert = false;
NODEBUG_EARLY_BAILOUT();
}
}
// We can if-convert this loop.
return CanIfConvert;
}
bool LoopVectorizationLegality::canVectorize() {
bool CanVectorize = true;
// We must have a loop in canonical form. Loops with indirectbr in them cannot
// be canonicalized.
if (!TheLoop->getLoopPreheader()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
return false;
}
// We can only vectorize innermost loops.
if (!TheLoop->empty()) {
ORE->emit(createMissedAnalysis("NotInnermostLoop")
<< "loop is not the innermost loop");
DEBUG(dbgs() << "LV: Not vectorizing - not the innermost loop.\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
}
// We must have a single backedge.
if (TheLoop->getNumBackEdges() != 1) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer"
<< ore::setExtraArgs()
<< " (Reason = multiple backedges)");
return false;
}
// We must have a single exiting block.
if (!TheLoop->getExitingBlock()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer"
<< ore::setExtraArgs()
<< " (Reason = early exits)");
return false;
}
// We only handle bottom-tested loops, i.e. loop in which the condition is
// checked at the end of each iteration. With that we can assume that all
// instructions in the loop are executed the same number of times.
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
return false;
}
// We need to have a loop header.
DEBUG(dbgs() << "LV: Found a loop: " << TheLoop->getHeader()->getName()
<< '\n');
// Check if we can if-convert non-single-bb loops.
unsigned NumBlocks = TheLoop->getNumBlocks();
if (NumBlocks != 1 && !canVectorizeWithIfConvert()) {
DEBUG(dbgs() << "LV: Not vectorizing - can't if-convert the loop.\n");
return false;
}
// ScalarEvolution needs to be able to find the exit count.
auto *SE = PSE.getSE();
const SCEV *ExitCount = PSE.getBackedgeTakenCount();
if (ExitCount == SE->getCouldNotCompute()) {
ORE->emit(createMissedAnalysis("CantComputeNumberOfIterations")
<< "could not determine number of loop iterations");
DEBUG(dbgs() <<
"LV: Not vectorizing - SCEV could not compute the loop exit count.\n");
return false;
}
// Check if we can vectorize the instructions and CFG in this loop.
if (!canVectorizeInstrs()) {
DEBUG(dbgs() <<
"LV: Not vectorizing - can't vectorize the instructions or CFG.\n");
return false;
}
// Go over each instruction and look at memory deps.
if (!canVectorizeMemory()) {
DEBUG(dbgs() <<
"LV: Can't vectorize due to memory conflicts.\n");
return false;
}
if (CanVectorize) {
// Collect all of the variables that remain uniform after vectorization.
collectLoopUniforms();
DEBUG(dbgs() << "LV: We can vectorize this loop"
<< (LAI->getRuntimePointerChecking()->Need
? " (with a runtime bound check)"
: "")
<< "!\n");
}
bool UseInterleaved = TTI->enableInterleavedAccessVectorization();
// If an override option has been passed in for interleaved accesses, use it.
if (EnableInterleavedMemAccesses.getNumOccurrences() > 0)
UseInterleaved = EnableInterleavedMemAccesses;
// Analyze interleaved memory accesses.
if (UseInterleaved)
InterleaveInfo.analyzeInterleaving(Strides);
unsigned SCEVThreshold = VectorizeSCEVCheckThreshold;
if (Hints->getForce() == LoopVectorizeHints::FK_Enabled)
SCEVThreshold = PragmaVectorizeSCEVCheckThreshold;
if (PSE.getUnionPredicate().getComplexity() > SCEVThreshold) {
ORE->emit(createMissedAnalysis("TooManySCEVRunTimeChecks")
<< "Too many SCEV assumptions need to be made and checked "
<< "at runtime");
DEBUG(dbgs() << "LV: Too many SCEV checks needed.\n");
return false;
}
// Okay! We can vectorize. At this point we don't have any other mem analysis
// which may limit our maximum vectorization factor, so just return true with
// no restrictions.
return CanVectorize;
}
static Type *convertPointerToIntegerType(const DataLayout &DL, Type *Ty) {
if (Ty->isPointerTy())
return DL.getIntPtrType(Ty);
// It is possible that char's or short's overflow when we ask for the loop's
// trip count, work around this by changing the type size.
if (Ty->getScalarSizeInBits() < 32)
return Type::getInt32Ty(Ty->getContext());
return Ty;
}
static Type *getWiderType(const DataLayout &DL, Type *Ty0, Type *Ty1) {
Ty0 = convertPointerToIntegerType(DL, Ty0);
Ty1 = convertPointerToIntegerType(DL, Ty1);
if (Ty0->getScalarSizeInBits() > Ty1->getScalarSizeInBits())
return Ty0;
return Ty1;
}
/// \brief Check that the instruction has outside loop users and is not an
/// identified reduction variable.
static bool hasOutsideLoopUser(const Loop *TheLoop, Instruction *Inst,
SmallPtrSetImpl<Value *> &AllowedExit) {
// Reduction and Induction instructions are allowed to have exit users. All
// other instructions must not have external users.
if (!AllowedExit.count(Inst))
// Check that all of the users of the loop are inside the BB.
for (User *U : Inst->users()) {
Instruction *UI = cast<Instruction>(U);
// This user may be a reduction exit value.
if (!TheLoop->contains(UI)) {
DEBUG(dbgs() << "LV: Found an outside user " << *UI << " for : "
<< *Inst << "\n");
return true;
}
}
return false;
}
void LoopVectorizationLegality::addInductionPhi(
PHINode *Phi, const InductionDescriptor &ID,
SmallPtrSetImpl<Value *> &AllowedExit) {
Inductions[Phi] = ID;
Type *PhiTy = Phi->getType();
const DataLayout &DL = Phi->getModule()->getDataLayout();
// Get the widest type.
if (!PhiTy->isFloatingPointTy()) {
if (!WidestIndTy)
WidestIndTy = convertPointerToIntegerType(DL, PhiTy);
else
WidestIndTy = getWiderType(DL, PhiTy, WidestIndTy);
}
// Int inductions are special because we only allow one IV.
if (ID.getKind() == InductionDescriptor::IK_IntInduction &&
ID.getConstIntStepValue() &&
ID.getConstIntStepValue()->isOne() &&
isa<Constant>(ID.getStartValue()) &&
cast<Constant>(ID.getStartValue())->isNullValue()) {
// Use the phi node with the widest type as induction. Use the last
// one if there are multiple (no good reason for doing this other
// than it is expedient). We've checked that it begins at zero and
// steps by one, so this is a canonical induction variable.
if (!PrimaryInduction || PhiTy == WidestIndTy)
PrimaryInduction = Phi;
}
// Both the PHI node itself, and the "post-increment" value feeding
// back into the PHI node may have external users.
AllowedExit.insert(Phi);
AllowedExit.insert(Phi->getIncomingValueForBlock(TheLoop->getLoopLatch()));
DEBUG(dbgs() << "LV: Found an induction variable.\n");
return;
}
bool LoopVectorizationLegality::canVectorizeInstrs() {
BasicBlock *Header = TheLoop->getHeader();
LAI = &(*GetLAA)(*TheLoop);
bool CanVectorize = true;
// Look for the attribute signaling the absence of NaNs.
Function &F = *Header->getParent();
HasFunNoNaNAttr =
F.getFnAttribute("no-nans-fp-math").getValueAsString() == "true";
// For each block in the loop.
for (Loop::block_iterator bb = TheLoop->block_begin(),
be = TheLoop->block_end();
bb != be; ++bb) {
// Scan the instructions in the block and look for hazards.
for (BasicBlock::iterator it = (*bb)->begin(), e = (*bb)->end(); it != e;
++it) {
if (PHINode *Phi = dyn_cast<PHINode>(it)) {
Type *PhiTy = Phi->getType();
// Check that this PHI type is allowed.
if (!PhiTy->isIntegerTy() && !PhiTy->isFloatingPointTy() &&
!PhiTy->isPointerTy()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi)
<< "loop control flow is not understood by vectorizer");
DEBUG(dbgs() <<
"LV: Not vectorizing - Found an non-int non-pointer PHI.\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
}
// If this PHINode is not in the header block, then we know that we
// can convert it to select during if-conversion. No need to check if
// the PHIs in this block are induction or reduction variables.
if (*bb != Header) {
// Check that this instruction has no outside users or is an
// identified reduction value with an outside user.
// TODO: For now, we ignore this case with uncounted loops and just
// focus on phis created in the header block.
if (!hasOutsideLoopUser(TheLoop, &*it, AllowedExit))
continue;
ORE->emit(createMissedAnalysis("NeitherInductionNorReduction", Phi)
<< "value could not be identified as "
"an induction or reduction variable");
return false;
}
// We only allow if-converted PHIs with exactly two incoming values.
if (Phi->getNumIncomingValues() != 2) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi)
<< "control flow not understood by vectorizer");
DEBUG(dbgs() <<
"LV: Not vectorizing - Phi with more than two incoming values.\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
continue;
}
RecurrenceDescriptor RedDes;
if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, PSE.getSE(),
RedDes)) {
if (RedDes.hasUnsafeAlgebra())
Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst());
AllowedExit.insert(RedDes.getLoopExitInstr());
Reductions[Phi] = RedDes;
DEBUG(dbgs() << "LV: Found a reduction variable " << *Phi << "\n");
continue;
}
InductionDescriptor ID;
RecurrenceDescriptor RecTmp;
// First we do a check to see if the phi is a recognizable reduction,
// if not we try to handle it as an induction variable if possible.
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID)) {
addInductionPhi(Phi, ID, AllowedExit);
if (ID.hasUnsafeAlgebra() && !HasFunNoNaNAttr)
Requirements->addUnsafeAlgebraInst(ID.getUnsafeAlgebraInst());
continue;
}
if (RecurrenceDescriptor::isFirstOrderRecurrence(Phi, TheLoop,
SinkAfter, DT)) {
FirstOrderRecurrences.insert(Phi);
continue;
}
// As a last resort, coerce the PHI to a AddRec expression
// and re-try classifying it a an induction PHI.
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID, true)) {
addInductionPhi(Phi, ID, AllowedExit);
continue;
}
ORE->emit(createMissedAnalysis("NonReductionValueUsedOutsideLoop", Phi)
<< "value that could not be identified as "
"reduction is used outside the loop");
DEBUG(dbgs() << "LV: Found an unidentified PHI." << *Phi << "\n");
return false;
} // end of PHI handling
// We handle calls that:
// * Are debug info intrinsics.
// * Have a mapping to an IR intrinsic.
// * Have a vector version available.
CallInst *CI = dyn_cast<CallInst>(it);
if (CI && !getVectorIntrinsicIDForCall(CI, TLI) &&
!isa<DbgInfoIntrinsic>(CI) &&
!(CI->getCalledFunction() && TLI &&
TLI->isFunctionVectorizable(CI->getCalledFunction()->getName()))) {
if (auto MSI = dyn_cast<MemSetInst>(CI)) {
if (VectorizeMemset && EnableScalableVectorisation &&
isLegalMaskedScatter(MSI->getValue()->getType())) {
const auto Length = MSI->getLength();
const auto IsVolatile = MSI->isVolatile();
// Alignment is clamped to yield an acceptable vector element type.
const auto Alignment =
std::min(MSI->getAlignmentCst()->getZExtValue(), (uint64_t) 8);
auto CL = dyn_cast<ConstantInt>(Length);
if (CL && (CL->getZExtValue() % Alignment == 0)
&& ((CL->getZExtValue() / Alignment) <=
VectorizerMemSetThreshold)
&& !IsVolatile) {
DEBUG(dbgs() << "LV: Found a vectorizable 'memset':\n" << *MSI);
continue;
}
}
}
if (CI->isInlineAsm())
ORE->emit(createMissedAnalysis("CantVectorizeCall")
<< "inline assembly call cannot be vectorized"
<< ore::setExtraArgs()
<< " (Location = " << ore::NV("Location", CI) << ")");
else {
auto *Callee = CI->getCalledFunction();
std::string CalleeName = Callee ? Callee->getName() : "[?]";
ORE->emit(createMissedAnalysis("CantVectorizeCall")
<< "call instruction cannot be vectorized"
<< ore::setExtraArgs()
<< " (Callee = " << CalleeName
<< ", Location = " << ore::NV("Location", CI) << ")");
}
DEBUG(dbgs() <<
"LV: Not vectorizing - found a non-intrinsic, non-libfunc callsite " <<
*CI << "\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
continue;
}
// Intrinsics such as powi,cttz and ctlz are legal to vectorize if the
// second argument is the same (i.e. loop invariant)
if (CI && hasVectorInstrinsicScalarOpd(
getVectorIntrinsicIDForCall(CI, TLI), 1)) {
auto *SE = PSE.getSE();
if (!SE->isLoopInvariant(PSE.getSCEV(CI->getOperand(1)), TheLoop)) {
ORE->emit(createMissedAnalysis("CantVectorizeIntrinsic", CI)
<< "intrinsic instruction cannot be vectorized");
DEBUG(dbgs() <<
"LV: Not vectorizing - found unvectorizable intrinsic " << *CI << "\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
continue;
}
}
// Check that the instruction return type is vectorizable.
// Also, we can't vectorize extractelement instructions.
if ((!VectorType::isValidElementType(it->getType()) &&
!it->getType()->isVoidTy()) ||
it->getType()->isFP128Ty() ||
isa<ExtractElementInst>(it)) {
ORE->emit(createMissedAnalysis("CantVectorizeInstructionReturnType", &*it)
<< "instruction return type cannot be vectorized");
DEBUG(dbgs() << "LV: Found unvectorizable type.\n");
DEBUG(dbgs() <<
"LV: Not vectorizing - found unvectorizable type " <<
*(it->getType()) << "\n");
CanVectorize = false;
NODEBUG_EARLY_BAILOUT();
continue;
}
if (StoreInst *SI = dyn_cast<StoreInst>(it)) {
Value *Ptr = SI->getPointerOperand();
auto *Ty = cast<PointerType>(Ptr->getType())->getElementType();
if (std::abs(isConsecutivePtr(Ptr)) != 1 && !LAI->isUniform(Ptr) &&
!isLegalMaskedScatter(Ty)) {
ORE->emit(createMissedAnalysis("CantVectorizeNonUnitStride", &*it)
<< "non consecutive store instructions cannot be "
<< "vectorized");
return false;
}
}
if (LoadInst *LI = dyn_cast<LoadInst>(it)) {
Value *Ptr = LI->getPointerOperand();
auto *Ty = cast<PointerType>(Ptr->getType())->getElementType();
if (std::abs(isConsecutivePtr(Ptr)) != 1 && !LAI->isUniform(Ptr) &&
!isLegalMaskedGather(Ty)) {
ORE->emit(createMissedAnalysis("CantVectorizeNonUnitStride", &*it)
<< "non consecutive load instructions cannot be "
<< "vectorized");
return false;
}
}
// Check that the stored type is vectorizable.
if (StoreInst *ST = dyn_cast<StoreInst>(it)) {
Type *T = ST->getValueOperand()->getType();
if (!VectorType::isValidElementType(T) || it->getType()->isFP128Ty()) {
ORE->emit(createMissedAnalysis("CantVectorizeStore", ST)
<< "store instruction cannot be vectorized");
return false;
}
// FP instructions can allow unsafe algebra, thus vectorizable by
// non-IEEE-754 compliant SIMD units.
// This applies to floating-point math operations and calls, not memory
// operations, shuffles, or casts, as they don't change precision or
// semantics.
} else if (it->getType()->isFloatingPointTy() &&
(CI || it->isBinaryOp()) && !it->hasUnsafeAlgebra()) {
DEBUG(dbgs() << "LV: Found FP op with unsafe algebra.\n");
Hints->setPotentiallyUnsafe();
}
// Reduction instructions are allowed to have exit users.
// All other instructions must not have external users.
//
// For uncounted loops we do allow induction variable
// escapees.
if (hasOutsideLoopUser(TheLoop, &*it, AllowedExit)) {
ORE->emit(createMissedAnalysis("ValueUsedOutsideLoop", &*it)
<< "value cannot be used outside the loop");
return false;
}
} // next instr.
}
if (!PrimaryInduction) {
DEBUG(dbgs() << "LV: Did not find one integer induction var.\n");
if (Inductions.empty()) {
ORE->emit(createMissedAnalysis("NoInductionVariable")
<< "loop induction variable could not be identified");
DEBUG(dbgs() <<
"LV: Not vectorizing - unable to identify loop induction variable.\n");
CanVectorize = false;
}
}
// Now we know the widest induction type, check if our found induction
// is the same size. If it's not, unset it here and InnerLoopVectorizer
// will create another.
if (PrimaryInduction && WidestIndTy != PrimaryInduction->getType())
PrimaryInduction = nullptr;
return CanVectorize;
}
void LoopVectorizationLegality::collectStridedAccess(Value *MemAccess) {
Value *Ptr = nullptr;
if (LoadInst *LI = dyn_cast<LoadInst>(MemAccess))
Ptr = LI->getPointerOperand();
else if (StoreInst *SI = dyn_cast<StoreInst>(MemAccess))
Ptr = SI->getPointerOperand();
else
return;
Value *Stride = getStrideFromPointer(Ptr, PSE.getSE(), TheLoop);
if (!Stride)
return;
DEBUG(dbgs() << "LV: Found a strided access that we can version");
DEBUG(dbgs() << " Ptr: " << *Ptr << " Stride: " << *Stride << "\n");
Strides[Ptr] = Stride;
StrideSet.insert(Stride);
}
void LoopVectorizationLegality::collectLoopUniforms() {
// We now know that the loop is vectorizable!
// Collect variables that will remain uniform after vectorization.
std::vector<Value *> Worklist;
BasicBlock *Latch = TheLoop->getLoopLatch();
// Start with the conditional branch and walk up the block.
Worklist.push_back(Latch->getTerminator()->getOperand(0));
// Also add all consecutive pointer values; these values will be uniform
// after vectorization (and subsequent cleanup) and, until revectorization is
// supported, all dependencies must also be uniform.
for (Loop::block_iterator B = TheLoop->block_begin(),
BE = TheLoop->block_end();
B != BE; ++B)
for (BasicBlock::iterator I = (*B)->begin(), IE = (*B)->end(); I != IE; ++I)
if (I->getType()->isPointerTy() && isConsecutivePtr(&*I))
Worklist.insert(Worklist.end(), I->op_begin(), I->op_end());
while (!Worklist.empty()) {
Instruction *I = dyn_cast<Instruction>(Worklist.back());
Worklist.pop_back();
// Look at instructions inside this loop.
// Stop when reaching PHI nodes.
// TODO: we need to follow values all over the loop, not only in this block.
if (!I || !TheLoop->contains(I) || isa<PHINode>(I))
continue;
// This is a known uniform.
Uniforms.insert(I);
// Insert all operands.
Worklist.insert(Worklist.end(), I->op_begin(), I->op_end());
}
}
bool LoopVectorizationLegality::canVectorizeMemory() {
LAI = &(*GetLAA)(*TheLoop);
InterleaveInfo.setLAI(LAI);
const OptimizationRemarkAnalysis *LAR = LAI->getReport();
if (LAR) {
OptimizationRemarkAnalysis VR(Hints->vectorizeAnalysisPassName(),
"loop not vectorized: ", *LAR);
ORE->emit(VR);
}
if (!LAI->canVectorizeMemory())
return false;
if (LAI->hasStoreToLoopInvariantAddress()) {
ScalarEvolution *SE = PSE.getSE();
std::list<StoreInst*> UnhandledStores;
// For each invariant address, check its last stored value is the result
// of one of our reductions and is unconditional.
for (StoreInst *SI : LAI->getInvariantStores()) {
bool FoundMatchingRecurrence = false;
for (auto &II : Reductions) {
RecurrenceDescriptor DS = II.second;
StoreInst *DSI = DS.IntermediateStore;
if (DSI && (DSI == SI) && !blockNeedsPredication(DSI->getParent())) {
FoundMatchingRecurrence = true;
break;
}
}
if (FoundMatchingRecurrence)
// Earlier stores to this address are effectively deadcode.
UnhandledStores.remove_if([SE, SI](StoreInst *I) {
return storeToSameAddress(SE, SI, I);
});
else
UnhandledStores.push_back(SI);
}
bool IsOK = UnhandledStores.empty();
// TODO: we should also validate against InvariantMemSets.
if (!IsOK) {
ORE->emit(createMissedAnalysis("CantVectorizeStoreToLoopInvariantAddress")
<< "write to a loop invariant address could not be vectorized");
DEBUG(dbgs() << "LV: We don't allow storing to uniform addresses\n");
return false;
}
}
Requirements->addRuntimePointerChecks(LAI->getNumRuntimePointerChecks());
PSE.addPredicate(LAI->getPSE().getUnionPredicate());
return true;
}
bool LoopVectorizationLegality::isInductionVariable(const Value *V) {
Value *In0 = const_cast<Value *>(V);
if (EnableScalableVectorisation) {
// TODO: Need to handle other arithmetic/logical instructions
Instruction *Inst = dyn_cast<Instruction>(In0);
if (Inst && Inst->getOpcode() == Instruction::Shl) {
Value *ShiftVal = Inst->getOperand(1);
if (!dyn_cast<ConstantInt>(ShiftVal))
return false;
In0 = Inst->getOperand(0);
}
}
PHINode *PN = dyn_cast_or_null<PHINode>(In0);
if (!PN)
return false;
return Inductions.count(PN);
}
bool LoopVectorizationLegality::isFirstOrderRecurrence(const PHINode *Phi) {
return FirstOrderRecurrences.count(Phi);
}
bool LoopVectorizationLegality::blockNeedsPredication(BasicBlock *BB) {
return LoopAccessInfo::blockNeedsPredication(BB, TheLoop, DT);
}
bool LoopVectorizationLegality::blockCanBePredicated(
BasicBlock *BB, SmallPtrSetImpl<Value *> &SafePtrs) {
const bool IsAnnotatedParallel = TheLoop->isAnnotatedParallel();
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
// Check that we don't have a constant expression that can trap as operand.
for (Instruction::op_iterator OI = it->op_begin(), OE = it->op_end();
OI != OE; ++OI) {
if (Constant *C = dyn_cast<Constant>(*OI))
if (C->canTrap())
return false;
}
// We might be able to hoist the load.
if (it->mayReadFromMemory()) {
LoadInst *LI = dyn_cast<LoadInst>(it);
if (!LI)
return false;
if (!SafePtrs.count(LI->getPointerOperand())) {
if (isLegalMaskedLoad(LI->getType(), LI->getPointerOperand()) ||
isLegalMaskedGather(LI->getType())) {
MaskedOp.insert(LI);
continue;
}
// !llvm.mem.parallel_loop_access implies if-conversion safety.
if (IsAnnotatedParallel)
continue;
return false;
}
}
// We don't predicate stores at the moment.
if (it->mayWriteToMemory()) {
StoreInst *SI = dyn_cast<StoreInst>(it);
// We only support predication of stores in basic blocks with one
// predecessor.
if (!SI)
return false;
// Build a masked store if it is legal for the target.
if (isLegalMaskedStore(SI->getValueOperand()->getType(),
SI->getPointerOperand()) ||
isLegalMaskedScatter(SI->getValueOperand()->getType())) {
MaskedOp.insert(SI);
continue;
}
bool isSafePtr = (SafePtrs.count(SI->getPointerOperand()) != 0);
bool isSinglePredecessor = SI->getParent()->getSinglePredecessor();
if (++NumPredStores > NumberOfStoresToPredicate || !isSafePtr ||
!isSinglePredecessor)
return false;
}
if (it->mayThrow())
return false;
// The instructions below can trap.
switch (it->getOpcode()) {
default:
continue;
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::URem:
case Instruction::SRem:
return false;
}
}
return true;
}
void InterleavedAccessInfo::collectConstStrideAccesses(
MapVector<Instruction *, StrideDescriptor> &AccessStrideInfo,
const ValueToValueMap &Strides) {
auto &DL = TheLoop->getHeader()->getModule()->getDataLayout();
// Since it's desired that the load/store instructions be maintained in
// "program order" for the interleaved access analysis, we have to visit the
// blocks in the loop in reverse postorder (i.e., in a topological order).
// Such an ordering will ensure that any load/store that may be executed
// before a second load/store will precede the second load/store in
// AccessStrideInfo.
LoopBlocksDFS DFS(TheLoop);
DFS.perform(LI);
for (BasicBlock *BB : make_range(DFS.beginRPO(), DFS.endRPO()))
for (auto &I : *BB) {
auto *LI = dyn_cast<LoadInst>(&I);
auto *SI = dyn_cast<StoreInst>(&I);
if (!LI && !SI)
continue;
Value *Ptr = getPointerOperand(&I);
// We don't check wrapping here because we don't know yet if Ptr will be
// part of a full group or a group with gaps. Checking wrapping for all
// pointers (even those that end up in groups with no gaps) will be overly
// conservative. For full groups, wrapping should be ok since if we would
// wrap around the address space we would do a memory access at nullptr
// even without the transformation. The wrapping checks are therefore
// deferred until after we've formed the interleaved groups.
int64_t Stride = getPtrStride(PSE, Ptr, TheLoop, Strides,
/*Assume=*/true, /*ShouldCheckWrap=*/false);
const SCEV *Scev = replaceSymbolicStrideSCEV(PSE, Strides, Ptr);
PointerType *PtrTy = dyn_cast<PointerType>(Ptr->getType());
uint64_t Size = DL.getTypeAllocSize(PtrTy->getElementType());
// An alignment of 0 means target ABI alignment.
unsigned Align = getMemInstAlignment(&I);
if (!Align)
Align = DL.getABITypeAlignment(PtrTy->getElementType());
AccessStrideInfo[&I] = StrideDescriptor(Stride, Scev, Size, Align);
}
}
// Analyze interleaved accesses and collect them into interleaved load and
// store groups.
//
// When generating code for an interleaved load group, we effectively hoist all
// loads in the group to the location of the first load in program order. When
// generating code for an interleaved store group, we sink all stores to the
// location of the last store. This code motion can change the order of load
// and store instructions and may break dependences.
//
// The code generation strategy mentioned above ensures that we won't violate
// any write-after-read (WAR) dependences.
//
// E.g., for the WAR dependence: a = A[i]; // (1)
// A[i] = b; // (2)
//
// The store group of (2) is always inserted at or below (2), and the load
// group of (1) is always inserted at or above (1). Thus, the instructions will
// never be reordered. All other dependences are checked to ensure the
// correctness of the instruction reordering.
//
// The algorithm visits all memory accesses in the loop in bottom-up program
// order. Program order is established by traversing the blocks in the loop in
// reverse postorder when collecting the accesses.
//
// We visit the memory accesses in bottom-up order because it can simplify the
// construction of store groups in the presence of write-after-write (WAW)
// dependences.
//
// E.g., for the WAW dependence: A[i] = a; // (1)
// A[i] = b; // (2)
// A[i + 1] = c; // (3)
//
// We will first create a store group with (3) and (2). (1) can't be added to
// this group because it and (2) are dependent. However, (1) can be grouped
// with other accesses that may precede it in program order. Note that a
// bottom-up order does not imply that WAW dependences should not be checked.
void InterleavedAccessInfo::analyzeInterleaving(
const ValueToValueMap &Strides) {
DEBUG(dbgs() << "LV: Analyzing interleaved accesses...\n");
// Holds all accesses with a constant stride.
MapVector<Instruction *, StrideDescriptor> AccessStrideInfo;
collectConstStrideAccesses(AccessStrideInfo, Strides);
if (AccessStrideInfo.empty())
return;
// Collect the dependences in the loop.
collectDependences();
// Holds all interleaved store groups temporarily.
SmallSetVector<InterleaveGroup *, 4> StoreGroups;
// Holds all interleaved load groups temporarily.
SmallSetVector<InterleaveGroup *, 4> LoadGroups;
// Search in bottom-up program order for pairs of accesses (A and B) that can
// form interleaved load or store groups. In the algorithm below, access A
// precedes access B in program order. We initialize a group for B in the
// outer loop of the algorithm, and then in the inner loop, we attempt to
// insert each A into B's group if:
//
// 1. A and B have the same stride,
// 2. A and B have the same memory object size, and
// 3. A belongs in B's group according to its distance from B.
//
// Special care is taken to ensure group formation will not break any
// dependences.
for (auto BI = AccessStrideInfo.rbegin(), E = AccessStrideInfo.rend();
BI != E; ++BI) {
Instruction *B = BI->first;
StrideDescriptor DesB = BI->second;
// Initialize a group for B if it has an allowable stride. Even if we don't
// create a group for B, we continue with the bottom-up algorithm to ensure
// we don't break any of B's dependences.
InterleaveGroup *Group = nullptr;
if (isStrided(DesB.Stride)) {
Group = getInterleaveGroup(B);
if (!Group) {
DEBUG(dbgs() << "LV: Creating an interleave group with:" << *B << '\n');
Group = createInterleaveGroup(B, DesB.Stride, DesB.Align);
}
if (B->mayWriteToMemory())
StoreGroups.insert(Group);
else
LoadGroups.insert(Group);
}
for (auto AI = std::next(BI); AI != E; ++AI) {
Instruction *A = AI->first;
StrideDescriptor DesA = AI->second;
// Our code motion strategy implies that we can't have dependences
// between accesses in an interleaved group and other accesses located
// between the first and last member of the group. Note that this also
// means that a group can't have more than one member at a given offset.
// The accesses in a group can have dependences with other accesses, but
// we must ensure we don't extend the boundaries of the group such that
// we encompass those dependent accesses.
//
// For example, assume we have the sequence of accesses shown below in a
// stride-2 loop:
//
// (1, 2) is a group | A[i] = a; // (1)
// | A[i-1] = b; // (2) |
// A[i-3] = c; // (3)
// A[i] = d; // (4) | (2, 4) is not a group
//
// Because accesses (2) and (3) are dependent, we can group (2) with (1)
// but not with (4). If we did, the dependent access (3) would be within
// the boundaries of the (2, 4) group.
if (!canReorderMemAccessesForInterleavedGroups(&*AI, &*BI)) {
// If a dependence exists and A is already in a group, we know that A
// must be a store since A precedes B and WAR dependences are allowed.
// Thus, A would be sunk below B. We release A's group to prevent this
// illegal code motion. A will then be free to form another group with
// instructions that precede it.
if (isInterleaved(A)) {
InterleaveGroup *StoreGroup = getInterleaveGroup(A);
StoreGroups.remove(StoreGroup);
releaseGroup(StoreGroup);
}
// If a dependence exists and A is not already in a group (or it was
// and we just released it), B might be hoisted above A (if B is a
// load) or another store might be sunk below A (if B is a store). In
// either case, we can't add additional instructions to B's group. B
// will only form a group with instructions that it precedes.
break;
}
// At this point, we've checked for illegal code motion. If either A or B
// isn't strided, there's nothing left to do.
if (!isStrided(DesA.Stride) || !isStrided(DesB.Stride))
continue;
// Ignore A if it's already in a group or isn't the same kind of memory
// operation as B.
if (isInterleaved(A) || A->mayReadFromMemory() != B->mayReadFromMemory())
continue;
// Check rules 1 and 2. Ignore A if its stride or size is different from
// that of B.
if (DesA.Stride != DesB.Stride || DesA.Size != DesB.Size)
continue;
// Ignore A if the memory object of A and B don't belong to the same
// address space
if (getMemInstAddressSpace(A) != getMemInstAddressSpace(B))
continue;
// Calculate the distance from A to B.
const SCEVConstant *DistToB = dyn_cast<SCEVConstant>(
PSE.getSE()->getMinusSCEV(DesA.Scev, DesB.Scev));
if (!DistToB)
continue;
int64_t DistanceToB = DistToB->getAPInt().getSExtValue();
// Check rule 3. Ignore A if its distance to B is not a multiple of the
// size.
if (DistanceToB % static_cast<int64_t>(DesB.Size))
continue;
// Ignore A if either A or B is in a predicated block. Although we
// currently prevent group formation for predicated accesses, we may be
// able to relax this limitation in the future once we handle more
// complicated blocks.
if (isPredicated(A->getParent()) || isPredicated(B->getParent()))
continue;
// The index of A is the index of B plus A's distance to B in multiples
// of the size.
int IndexA =
Group->getIndex(B) + DistanceToB / static_cast<int64_t>(DesB.Size);
// Try to insert A into B's group.
if (Group->insertMember(A, IndexA, DesA.Align)) {
DEBUG(dbgs() << "LV: Inserted:" << *A << '\n'
<< " into the interleave group with" << *B << '\n');
InterleaveGroupMap[A] = Group;
// Set the first load in program order as the insert position.
if (A->mayReadFromMemory())
Group->setInsertPos(A);
}
} // Iteration over A accesses.
} // Iteration over B accesses.
// Remove interleaved store groups with gaps.
for (InterleaveGroup *Group : StoreGroups)
if (Group->getNumMembers() != Group->getFactor())
releaseGroup(Group);
// Remove interleaved groups with gaps (currently only loads) whose memory
// accesses may wrap around. We have to revisit the getPtrStride analysis,
// this time with ShouldCheckWrap=true, since collectConstStrideAccesses does
// not check wrapping (see documentation there).
// FORNOW we use Assume=false;
// TODO: Change to Assume=true but making sure we don't exceed the threshold
// of runtime SCEV assumptions checks (thereby potentially failing to
// vectorize altogether).
// Additional optional optimizations:
// TODO: If we are peeling the loop and we know that the first pointer doesn't
// wrap then we can deduce that all pointers in the group don't wrap.
// This means that we can forcefully peel the loop in order to only have to
// check the first pointer for no-wrap. When we'll change to use Assume=true
// we'll only need at most one runtime check per interleaved group.
//
for (InterleaveGroup *Group : LoadGroups) {
// Case 1: A full group. Can Skip the checks; For full groups, if the wide
// load would wrap around the address space we would do a memory access at
// nullptr even without the transformation.
if (Group->getNumMembers() == Group->getFactor())
continue;
// Case 2: If first and last members of the group don't wrap this implies
// that all the pointers in the group don't wrap.
// So we check only group member 0 (which is always guaranteed to exist),
// and group member Factor - 1; If the latter doesn't exist we rely on
// peeling (if it is a non-reveresed accsess -- see Case 3).
Value *FirstMemberPtr = getPointerOperand(Group->getMember(0));
if (!getPtrStride(PSE, FirstMemberPtr, TheLoop, Strides, /*Assume=*/false,
/*ShouldCheckWrap=*/true)) {
DEBUG(dbgs() << "LV: Invalidate candidate interleaved group due to "
"first group member potentially pointer-wrapping.\n");
releaseGroup(Group);
continue;
}
Instruction *LastMember = Group->getMember(Group->getFactor() - 1);
if (LastMember) {
Value *LastMemberPtr = getPointerOperand(LastMember);
if (!getPtrStride(PSE, LastMemberPtr, TheLoop, Strides, /*Assume=*/false,
/*ShouldCheckWrap=*/true)) {
DEBUG(dbgs() << "LV: Invalidate candidate interleaved group due to "
"last group member potentially pointer-wrapping.\n");
releaseGroup(Group);
}
} else {
// Case 3: A non-reversed interleaved load group with gaps: We need
// to execute at least one scalar epilogue iteration. This will ensure
// we don't speculatively access memory out-of-bounds. We only need
// to look for a member at index factor - 1, since every group must have
// a member at index zero.
if (Group->isReverse()) {
releaseGroup(Group);
continue;
}
DEBUG(dbgs() << "LV: Interleaved group requires epilogue iteration.\n");
RequiresScalarEpilogue = true;
}
}
}
static TargetTransformInfo::ReductionFlags
getReductionFlagsFromDesc(RecurrenceDescriptor Rdx) {
using RD = RecurrenceDescriptor;
RD::RecurrenceKind RecKind = Rdx.getRecurrenceKind();
TargetTransformInfo::ReductionFlags Flags;
Flags.IsOrdered = Rdx.isOrdered();
if (RecKind == RD::RK_IntegerMinMax || RecKind == RD::RK_FloatMinMax) {
auto MMKind = Rdx.getMinMaxRecurrenceKind();
Flags.IsSigned = MMKind == RD::MRK_SIntMax || MMKind == RD::MRK_SIntMin;
Flags.IsMaxOp = MMKind == RD::MRK_SIntMax || MMKind == RD::MRK_FloatMax;
}
return Flags;
}
VectorizationFactor
LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize) {
bool FixedWidth = !EnableScalableVectorisation;
int UserVStyle = Hints->getStyle();
if (UserVStyle != LoopVectorizeHints::SK_Unspecified) {
FixedWidth = UserVStyle == LoopVectorizeHints::SK_Fixed;
DEBUG(dbgs() << "LV: Using user vectorization style of "
<< (FixedWidth ? "fixed" : "scaled") << " width.\n");
}
// Width 1 means no vectorize
VectorizationFactor Factor = { 1U, 0U, FixedWidth };
if (OptForSize && Legal->getRuntimePointerChecking()->Need) {
ORE->emit(createMissedAnalysis("CantVersionLoopWithOptForSize")
<< "runtime pointer checks needed. Enable vectorization of this "
"loop with '#pragma clang loop vectorize(enable)' when "
"compiling with -Os/-Oz");
DEBUG(dbgs() <<
"LV: Aborting. Runtime ptr check is required with -Os/-Oz.\n");
Factor.isFixed = true;
return Factor;
}
if (!EnableCondStoresVectorization && Legal->getNumPredStores()) {
ORE->emit(createMissedAnalysis("ConditionalStore")
<< "store that is conditionally executed prevents vectorization");
DEBUG(dbgs() << "LV: No vectorization. There are conditional stores.\n");
Factor.isFixed = true;
return Factor;
}
// Find the trip count.
unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n');
MinBWs = computeMinimumValueSizes(TheLoop->getBlocks(), *DB, &TTI);
unsigned SmallestType, WidestType;
std::tie(SmallestType, WidestType) = getSmallestAndWidestTypes();
unsigned WidestRegister = TTI.getRegisterBitWidth(true);
unsigned MaxSafeDepDist = -1U;
// Get the maximum safe dependence distance in bits computed by LAA. If the
// loop contains any interleaved accesses, we divide the dependence distance
// by the maximum interleave factor of all interleaved groups. Note that
// although the division ensures correctness, this is a fairly conservative
// computation because the maximum distance computed by LAA may not involve
// any of the interleaved accesses.
if (Legal->getMaxSafeDepDistBytes() != -1U)
MaxSafeDepDist =
Legal->getMaxSafeDepDistBytes() * 8 / Legal->getMaxInterleaveFactor();
// For the case when the register size is unknown we cannot vectorise loops
// with data dependencies in a scalable manner. However, when the
// architecture provides an upper bound, we can query that before reverting
// to fixed width vectors.
if (MaxSafeDepDist < TTI.getRegisterBitWidthUpperBound(true)) {
Factor.isFixed = true;
// LAA may have assumed we can do strided during analysis
if (Legal->getRuntimePointerChecking()->Strided &&
TTI.canVectorizeNonUnitStrides(true)) {
DEBUG(dbgs() <<
"LV: Not vectorizing, can't do strided accesses on target.\n");
ORE->emit(createMissedAnalysis("StridedAccess")
<< "Target doesn't support vectorizing strided accesses.");
Factor.Width = 1;
return Factor;
}
}
WidestRegister =
((WidestRegister < MaxSafeDepDist) ? WidestRegister : MaxSafeDepDist);
unsigned MaxVectorSize = WidestRegister / WidestType;
DEBUG(dbgs() << "LV: The Smallest and Widest types: " << SmallestType << " / "
<< WidestType << " bits.\n");
DEBUG(dbgs() << "LV: The Widest register is: " << WidestRegister
<< " bits.\n");
if (MaxVectorSize == 0) {
DEBUG(dbgs() << "LV: The target has no vector registers.\n");
MaxVectorSize = 1;
}
assert(MaxVectorSize <= 64 && "Did not expect to pack so many elements"
" into one vector!");
unsigned VF = MaxVectorSize;
if (MaximizeBandwidth && !OptForSize) {
// Collect all viable vectorization factors.
SmallVector<unsigned, 8> VFs;
unsigned NewMaxVectorSize = WidestRegister / SmallestType;
for (unsigned VS = MaxVectorSize; VS <= NewMaxVectorSize; VS *= 2)
VFs.push_back(VS);
// For each VF calculate its register usage.
auto RUs = calculateRegisterUsage(VFs);
// Select the largest VF which doesn't require more registers than existing
// ones.
unsigned TargetNumRegisters = TTI.getNumberOfRegisters(true);
for (int i = RUs.size() - 1; i >= 0; --i) {
if (RUs[i].MaxLocalUsers <= TargetNumRegisters) {
VF = VFs[i];
break;
}
}
}
// If we optimize the program for size, avoid creating the tail loop.
if (OptForSize) {
// If we are unable to calculate the trip count then don't try to vectorize.
if (TC < 2) {
ORE->emit(
createMissedAnalysis("UnknownLoopCountComplexCFG")
<< "unable to calculate the loop count due to complex control flow");
DEBUG(dbgs() << "LV: Aborting. A tail loop is required with -Os/-Oz.\n");
if (Factor.Width < 2)
Factor.isFixed = true;
return Factor;
}
// Find the maximum SIMD width that can fit within the trip count.
VF = TC % MaxVectorSize;
if (VF == 0)
VF = MaxVectorSize;
else {
// If the trip count that we found modulo the vectorization factor is not
// zero then we require a tail.
ORE->emit(createMissedAnalysis("NoTailLoopWithOptForSize")
<< "cannot optimize for size and vectorize at the "
"same time. Enable vectorization of this loop "
"with '#pragma clang loop vectorize(enable)' "
"when compiling with -Os/-Oz");
DEBUG(dbgs() << "LV: Aborting. A tail loop is required with -Os/-Oz.\n");
Factor.isFixed = true;
return Factor;
}
}
// If the target does not have a scalable reduction intrinsic, abort.
if (!Factor.isFixed) {
for (auto Rdx : *Legal->getReductionVars()) {
auto Flags = getReductionFlagsFromDesc(Rdx.second);
unsigned Opc = RecurrenceDescriptor::getRecurrenceBinOp(
Rdx.second.getRecurrenceKind());
if (!TTI.canReduceInVector(Opc, Rdx.second.getRecurrenceType(), Flags)) {
ORE->emit(createMissedAnalysis("MissingReductionOperation")
<< "Cannot use scalable vectorization due to an unsupported "
"reduction operation. Use fixed width vectorization.");
DEBUG(dbgs() << "LV: Aborting. Unsupported reduction for scalable "
"vectorization.\n");
Factor.isFixed = true;
Factor.Width = 1;
return Factor;
}
}
}
int UserVF = Hints->getWidth();
if (UserVF != 0) {
assert(isPowerOf2_32(UserVF) && "VF needs to be a power of two");
DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n");
Factor.Width = UserVF;
if (Factor.Width < 2)
Factor.isFixed = true;
return Factor;
}
float Cost = expectedCost({/*Width=*/1, 0, /*isFixed=*/true}).first;
#ifndef NDEBUG
const float ScalarCost = Cost;
#endif /* NDEBUG */
Factor.Width = 1;
DEBUG(dbgs() << "LV: Scalar loop costs: " << (int)ScalarCost << ".\n");
bool ForceVectorization = Hints->getForce() == LoopVectorizeHints::FK_Enabled;
// Ignore scalar width, because the user explicitly wants vectorization.
if (ForceVectorization && VF > 1) {
Factor.Width = 2;
Cost = expectedCost(Factor).first / (float)Factor.Width;
}
VectorizationFactor PotentialFactor = Factor;
for (unsigned i = 2; i <= VF; i *= 2) {
// Notice that the vector loop needs to be executed less times, so
// we need to divide the cost of the vector loops by the width of
// the vector elements.
PotentialFactor.Width = i;
VectorizationCostTy C = expectedCost(PotentialFactor);
float VectorCost = C.first / (float)i;
DEBUG(dbgs() << "LV: Vector loop of width " << i
<< " costs: " << (int)VectorCost << ".\n");
if (!C.second && !ForceVectorization) {
DEBUG(
dbgs() << "LV: Not considering vector loop of width " << i
<< " because it will not generate any vector instructions.\n");
continue;
}
if (VectorCost < Cost) {
Cost = VectorCost;
Factor = PotentialFactor;
}
}
DEBUG(if (ForceVectorization && Factor.Width > 1 && Cost >= ScalarCost) dbgs()
<< "LV: Vectorization seems to be not beneficial, "
<< "but was forced by a user.\n");
Factor.Cost = Factor.Width * Cost;
if (Factor.Width < 2)
Factor.isFixed = true;
DEBUG(dbgs() << "LV: Selecting VF: " << (Factor.isFixed ? "" : "n x ") <<
Factor.Width << ".\n");
return Factor;
}
std::pair<unsigned, unsigned>
LoopVectorizationCostModel::getSmallestAndWidestTypes() {
unsigned MinWidth = -1U;
unsigned MaxWidth = 8;
const DataLayout &DL = TheFunction->getParent()->getDataLayout();
// For each block.
for (Loop::block_iterator bb = TheLoop->block_begin(),
be = TheLoop->block_end();
bb != be; ++bb) {
BasicBlock *BB = *bb;
// For each instruction in the loop.
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
Type *T = it->getType();
// Skip ignored values.
if (ValuesToIgnore.count(&*it))
continue;
// Only examine Loads, Stores and PHINodes.
if (!isa<LoadInst>(it) && !isa<StoreInst>(it) && !isa<PHINode>(it))
continue;
// Examine PHI nodes that are reduction variables. Update the type to
// account for the recurrence type.
if (PHINode *PN = dyn_cast<PHINode>(it)) {
if (!Legal->isReductionVariable(PN))
continue;
RecurrenceDescriptor RdxDesc = (*Legal->getReductionVars())[PN];
T = RdxDesc.getRecurrenceType();
}
// Examine the stored values.
if (StoreInst *ST = dyn_cast<StoreInst>(it))
T = ST->getValueOperand()->getType();
// Ignore loaded pointer types and stored pointer types that are not
// vectorizable.
//
// FIXME: The check here attempts to predict whether a load or store will
// be vectorized. We only know this for certain after a VF has
// been selected. Here, we assume that if an access can be
// vectorized, it will be. We should also look at extending this
// optimization to non-pointer types.
//
if (T->isPointerTy() && !isConsecutiveLoadOrStore(&*it) &&
!Legal->isAccessInterleaved(&*it) && !Legal->isLegalGatherOrScatter(&*it))
continue;
MinWidth = std::min(MinWidth,
(unsigned)DL.getTypeSizeInBits(T->getScalarType()));
MaxWidth = std::max(MaxWidth,
(unsigned)DL.getTypeSizeInBits(T->getScalarType()));
}
}
return {MinWidth, MaxWidth};
}
unsigned
LoopVectorizationCostModel::selectInterleaveCount(bool OptForSize,
VectorizationFactor VF,
unsigned LoopCost) {
// -- The interleave heuristics --
// We interleave the loop in order to expose ILP and reduce the loop overhead.
// There are many micro-architectural considerations that we can't predict
// at this level. For example, frontend pressure (on decode or fetch) due to
// code size, or the number and capabilities of the execution ports.
//
// We use the following heuristics to select the interleave count:
// 1. If the code has reductions, then we interleave to break the cross
// iteration dependency.
// 2. If the loop is really small, then we interleave to reduce the loop
// overhead.
// 3. We don't interleave if we think that we will spill registers to memory
// due to the increased register pressure.
// TODO: revisit this decision but for now it is not worth considering
if (EnableVectorPredication && !VF.isFixed)
return 1;
// When we optimize for size, we don't interleave.
if (OptForSize)
return 1;
// We used the distance for the interleave count.
if (Legal->getMaxSafeDepDistBytes() != -1U)
return 1;
// Do not interleave loops with a relatively small trip count.
unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
if (TC > 1 && TC < TinyTripCountInterleaveThreshold)
return 1;
// Ordered reductions can't be used with interleaving.
for (auto &Rdx : *Legal->getReductionVars())
if (Rdx.second.isOrdered())
return 1;
unsigned TargetNumRegisters = TTI.getNumberOfRegisters(VF.Width > 1);
DEBUG(dbgs() << "LV: The target has " << TargetNumRegisters
<< " registers\n");
if (VF.Width == 1) {
if (ForceTargetNumScalarRegs.getNumOccurrences() > 0)
TargetNumRegisters = ForceTargetNumScalarRegs;
} else {
if (ForceTargetNumVectorRegs.getNumOccurrences() > 0)
TargetNumRegisters = ForceTargetNumVectorRegs;
}
RegisterUsage R = calculateRegisterUsage({VF.Width})[0];
// We divide by these constants so assume that we have at least one
// instruction that uses at least one register.
R.MaxLocalUsers = std::max(R.MaxLocalUsers, 1U);
R.NumInstructions = std::max(R.NumInstructions, 1U);
// We calculate the interleave count using the following formula.
// Subtract the number of loop invariants from the number of available
// registers. These registers are used by all of the interleaved instances.
// Next, divide the remaining registers by the number of registers that is
// required by the loop, in order to estimate how many parallel instances
// fit without causing spills. All of this is rounded down if necessary to be
// a power of two. We want power of two interleave count to simplify any
// addressing operations or alignment considerations.
unsigned IC = PowerOf2Floor((TargetNumRegisters - R.LoopInvariantRegs) /
R.MaxLocalUsers);
// Don't count the induction variable as interleaved.
if (EnableIndVarRegisterHeur)
IC = PowerOf2Floor((TargetNumRegisters - R.LoopInvariantRegs - 1) /
std::max(1U, (R.MaxLocalUsers - 1)));
// Clamp the interleave ranges to reasonable counts.
unsigned MaxInterleaveCount = TTI.getMaxInterleaveFactor(VF.Width);
// Check if the user has overridden the max.
if (VF.Width == 1) {
if (ForceTargetMaxScalarInterleaveFactor.getNumOccurrences() > 0)
MaxInterleaveCount = ForceTargetMaxScalarInterleaveFactor;
} else {
if (ForceTargetMaxVectorInterleaveFactor.getNumOccurrences() > 0)
MaxInterleaveCount = ForceTargetMaxVectorInterleaveFactor;
}
// If we did not calculate the cost for VF (because the user selected the VF)
// then we calculate the cost of VF here.
if (LoopCost == 0)
LoopCost = expectedCost(VF).first;
// Clamp the calculated IC to be between the 1 and the max interleave count
// that the target allows.
if (IC > MaxInterleaveCount)
IC = MaxInterleaveCount;
else if (IC < 1)
IC = 1;
// Interleave if we vectorized this loop and there is a reduction that could
// benefit from interleaving.
if (VF.Width > 1 && Legal->getReductionVars()->size()) {
DEBUG(dbgs() << "LV: Interleaving because of reductions.\n");
return IC;
}
// Note that if we've already vectorized the loop we will have done the
// runtime check and so interleaving won't require further checks.
bool InterleavingRequiresRuntimePointerCheck =
(VF.Width == 1 && Legal->getRuntimePointerChecking()->Need);
// We want to interleave small loops in order to reduce the loop overhead and
// potentially expose ILP opportunities.
DEBUG(dbgs() << "LV: Loop cost is " << LoopCost << '\n');
if (!InterleavingRequiresRuntimePointerCheck && LoopCost < SmallLoopCost) {
// We assume that the cost overhead is 1 and we use the cost model
// to estimate the cost of the loop and interleave until the cost of the
// loop overhead is about 5% of the cost of the loop.
unsigned SmallIC =
std::min(IC, (unsigned)PowerOf2Floor(SmallLoopCost / LoopCost));
// Interleave until store/load ports (estimated by max interleave count) are
// saturated.
unsigned NumStores = Legal->getNumStores();
unsigned NumLoads = Legal->getNumLoads();
unsigned StoresIC = IC / (NumStores ? NumStores : 1);
unsigned LoadsIC = IC / (NumLoads ? NumLoads : 1);
// If we have a scalar reduction (vector reductions are already dealt with
// by this point), we can increase the critical path length if the loop
// we're interleaving is inside another loop. Limit, by default to 2, so the
// critical path only gets increased by one reduction operation.
if (Legal->getReductionVars()->size() && TheLoop->getLoopDepth() > 1) {
unsigned F = static_cast<unsigned>(MaxNestedScalarReductionIC);
SmallIC = std::min(SmallIC, F);
StoresIC = std::min(StoresIC, F);
LoadsIC = std::min(LoadsIC, F);
}
if (EnableLoadStoreRuntimeInterleave &&
std::max(StoresIC, LoadsIC) > SmallIC) {
DEBUG(dbgs() << "LV: Interleaving to saturate store or load ports.\n");
return std::max(StoresIC, LoadsIC);
}
DEBUG(dbgs() << "LV: Interleaving to reduce branch cost.\n");
return SmallIC;
}
// Interleave if this is a large loop (small loops are already dealt with by
// this point) that could benefit from interleaving.
bool HasReductions = (Legal->getReductionVars()->size() > 0);
if (TTI.enableAggressiveInterleaving(HasReductions)) {
DEBUG(dbgs() << "LV: Interleaving to expose ILP.\n");
return IC;
}
DEBUG(dbgs() << "LV: Not Interleaving.\n");
return 1;
}
SmallVector<LoopVectorizationCostModel::RegisterUsage, 8>
LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<unsigned> VFs) {
// This function calculates the register usage by measuring the highest number
// of values that are alive at a single location. Obviously, this is a very
// rough estimation. We scan the loop in a topological order in order and
// assign a number to each instruction. We use RPO to ensure that defs are
// met before their users. We assume that each instruction that has in-loop
// users starts an interval. We record every time that an in-loop value is
// used, so we have a list of the first and last occurrences of each
// instruction. Next, we transpose this data structure into a multi map that
// holds the list of intervals that *end* at a specific location. This multi
// map allows us to perform a linear search. We scan the instructions linearly
// and record each time that a new interval starts, by placing it in a set.
// If we find this value in the multi-map then we remove it from the set.
// The max register usage is the maximum size of the set.
// We also search for instructions that are defined outside the loop, but are
// used inside the loop. We need this number separately from the max-interval
// usage number because when we unroll, loop-invariant values do not take
// more register.
LoopBlocksDFS DFS(TheLoop);
DFS.perform(LI);
RegisterUsage RU;
RU.NumInstructions = 0;
// Each 'key' in the map opens a new interval. The values
// of the map are the index of the 'last seen' usage of the
// instruction that is the key.
typedef DenseMap<Instruction *, unsigned> IntervalMap;
// Maps instruction to its index.
DenseMap<unsigned, Instruction *> IdxToInstr;
// Marks the end of each interval.
IntervalMap EndPoint;
// Saves the list of instruction indices that are used in the loop.
SmallSet<Instruction *, 8> Ends;
// Saves the list of values that are used in the loop but are
// defined outside the loop, such as arguments and constants.
SmallPtrSet<Value *, 8> LoopInvariants;
unsigned Index = 0;
for (LoopBlocksDFS::RPOIterator bb = DFS.beginRPO(), be = DFS.endRPO();
bb != be; ++bb) {
RU.NumInstructions += (*bb)->size();
for (Instruction &I : **bb) {
IdxToInstr[Index++] = &I;
// Save the end location of each USE.
for (unsigned i = 0; i < I.getNumOperands(); ++i) {
Value *U = I.getOperand(i);
Instruction *Instr = dyn_cast<Instruction>(U);
// Ignore non-instruction values such as arguments, constants, etc.
if (!Instr)
continue;
// If this instruction is outside the loop then record it and continue.
if (!TheLoop->contains(Instr)) {
LoopInvariants.insert(Instr);
continue;
}
// Overwrite previous end points.
EndPoint[Instr] = Index;
Ends.insert(Instr);
}
}
}
// Saves the list of intervals that end with the index in 'key'.
typedef SmallVector<Instruction *, 2> InstrList;
DenseMap<unsigned, InstrList> TransposeEnds;
// Transpose the EndPoints to a list of values that end at each index.
for (IntervalMap::iterator it = EndPoint.begin(), e = EndPoint.end(); it != e;
++it)
TransposeEnds[it->second].push_back(it->first);
SmallSet<Instruction *, 8> OpenIntervals;
// Get the size of the widest register.
unsigned MaxSafeDepDist = -1U;
if (Legal->getMaxSafeDepDistBytes() != -1U)
MaxSafeDepDist = Legal->getMaxSafeDepDistBytes() * 8;
unsigned WidestRegister =
std::min(TTI.getRegisterBitWidth(true), MaxSafeDepDist);
const DataLayout &DL = TheFunction->getParent()->getDataLayout();
SmallVector<RegisterUsage, 8> RUs(VFs.size());
SmallVector<unsigned, 8> MaxUsages(VFs.size(), 0);
DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
// A lambda that gets the register usage for the given type and VF.
auto GetRegUsage = [&DL, WidestRegister](Type *Ty, unsigned VF) {
if (Ty->isTokenTy())
return 0U;
unsigned TypeSize = DL.getTypeSizeInBits(Ty->getScalarType());
return std::max<unsigned>(1, VF * TypeSize / WidestRegister);
};
for (unsigned int i = 0; i < Index; ++i) {
Instruction *I = IdxToInstr[i];
// Ignore instructions that are never used within the loop.
if (!Ends.count(I))
continue;
// Remove all of the instructions that end at this location.
InstrList &List = TransposeEnds[i];
for (unsigned int j = 0, e = List.size(); j < e; ++j)
OpenIntervals.erase(List[j]);
// Skip ignored values.
if (ValuesToIgnore.count(I))
continue;
// For each VF find the maximum usage of registers.
for (unsigned j = 0, e = VFs.size(); j < e; ++j) {
if (VFs[j] == 1) {
MaxUsages[j] = std::max(MaxUsages[j], OpenIntervals.size());
continue;
}
// Count the number of live intervals.
unsigned RegUsage = 0;
for (auto Inst : OpenIntervals) {
// Skip ignored values for VF > 1.
if (VecValuesToIgnore.count(Inst))
continue;
RegUsage += GetRegUsage(Inst->getType(), VFs[j]);
}
MaxUsages[j] = std::max(MaxUsages[j], RegUsage);
}
DEBUG(dbgs() << "LV(REG): At #" << i << " Interval # "
<< OpenIntervals.size() << '\n');
// Add the current instruction to the list of open intervals.
OpenIntervals.insert(I);
}
for (unsigned i = 0, e = VFs.size(); i < e; ++i) {
unsigned Invariant = 0;
if (VFs[i] == 1)
Invariant = LoopInvariants.size();
else {
for (auto Inst : LoopInvariants)
Invariant += GetRegUsage(Inst->getType(), VFs[i]);
}
DEBUG(dbgs() << "LV(REG): VF = " << VFs[i] << '\n');
DEBUG(dbgs() << "LV(REG): Found max usage: " << MaxUsages[i] << '\n');
DEBUG(dbgs() << "LV(REG): Found invariant usage: " << Invariant << '\n');
DEBUG(dbgs() << "LV(REG): LoopSize: " << RU.NumInstructions << '\n');
RU.LoopInvariantRegs = Invariant;
RU.MaxLocalUsers = MaxUsages[i];
RUs[i] = RU;
}
return RUs;
}
LoopVectorizationCostModel::VectorizationCostTy
LoopVectorizationCostModel::expectedCost(VectorizationFactor VF) {
VectorizationCostTy Cost;
// For each block.
for (Loop::block_iterator bb = TheLoop->block_begin(),
be = TheLoop->block_end();
bb != be; ++bb) {
VectorizationCostTy BlockCost;
BasicBlock *BB = *bb;
// For each instruction in the old loop.
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
// Skip dbg intrinsics.
if (isa<DbgInfoIntrinsic>(it))
continue;
// Skip ignored values.
if (ValuesToIgnore.count(&*it))
continue;
VectorizationCostTy C = getInstructionCost(&*it, VF);
// Check if we should override the cost.
if (ForceTargetInstructionCost.getNumOccurrences() > 0)
C.first = ForceTargetInstructionCost;
BlockCost.first += C.first;
BlockCost.second |= C.second;
DEBUG(dbgs() << "LV: Found an estimated cost of " << C.first
<< " for VF " << (VF.isFixed ? "" : "n x ") << VF.Width
<< " For instruction: " << *it << '\n');
}
// We assume that if-converted blocks have a 50% chance of being executed.
// When the code is scalar then some of the blocks are avoided due to CF.
// When the code is vectorized we execute all code paths.
if (VF.Width == 1 && Legal->blockNeedsPredication(*bb))
BlockCost.first /= 2;
Cost.first += BlockCost.first;
Cost.second |= BlockCost.second;
}
return Cost;
}
/// \brief Check if the load/store instruction \p I may be translated into
/// gather/scatter during vectorization.
///
/// Pointer \p Ptr specifies address in memory for the given scalar memory
/// instruction. We need it to retrieve data type.
/// Using gather/scatter is possible when it is supported by target.
/*
static bool isGatherOrScatterLegal(Instruction *I, Value *Ptr,
LoopVectorizationLegality *Legal) {
Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType();
return (isa<LoadInst>(I) && Legal->isLegalMaskedGather(DataTy)) ||
(isa<StoreInst>(I) && Legal->isLegalMaskedScatter(DataTy));
}
*/
/// \brief Check whether the address computation for a non-consecutive memory
/// access looks like an unlikely candidate for being merged into the indexing
/// mode.
///
/// We look for a GEP which has one index that is an induction variable and all
/// other indices are loop invariant. If the stride of this access is also
/// within a small bound we decide that this address computation can likely be
/// merged into the addressing mode.
/// In all other cases, we identify the address computation as complex.
/*
static bool isLikelyComplexAddressComputation(Value *Ptr,
LoopVectorizationLegality *Legal,
ScalarEvolution *SE,
const Loop *TheLoop) {
GetElementPtrInst *Gep = dyn_cast<GetElementPtrInst>(Ptr);
if (!Gep)
return true;
// We are looking for a gep with all loop invariant indices except for one
// which should be an induction variable.
unsigned NumOperands = Gep->getNumOperands();
for (unsigned i = 1; i < NumOperands; ++i) {
Value *Opd = Gep->getOperand(i);
if (!SE->isLoopInvariant(SE->getSCEV(Opd), TheLoop) &&
!Legal->isInductionVariable(Opd))
return true;
}
// Now we know we have a GEP ptr, %inv, %ind, %inv. Make sure that the step
// can likely be merged into the address computation.
unsigned MaxMergeDistance = 64;
const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(Ptr));
if (!AddRec)
return true;
// Check the step is constant.
const SCEV *Step = AddRec->getStepRecurrence(*SE);
// Calculate the pointer stride and check if it is consecutive.
const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
if (!C)
return true;
const APInt &APStepVal = C->getAPInt();
// Huge step value - give up.
if (APStepVal.getBitWidth() > 64)
return true;
int64_t StepVal = APStepVal.getSExtValue();
return StepVal > MaxMergeDistance;
}
*/
static bool isStrideMul(Instruction *I, LoopVectorizationLegality *Legal) {
return Legal->hasStride(I->getOperand(0)) ||
Legal->hasStride(I->getOperand(1));
}
// Given a Chain
// A -> B -> Z,
// where:
// A = s/zext
// B = add
// C = trunc
// Check this is one of
// s/zext(i32) -> add -> trunc(valtype)
static bool isPartOfPromotedAdd(Instruction *I, Type **OrigType) {
Instruction *TruncOp = I;
// If I is one of step A, find step C
if ((I->getOpcode() == Instruction::ZExt ||
I->getOpcode() == Instruction::SExt)) {
// Confirm that s/zext is *only* used for the add
for(int K=0; K<2; ++K) {
if (!TruncOp->hasOneUse())
return false;
TruncOp = dyn_cast<Instruction>(TruncOp->user_back());
}
}
// If I is one of step B, find step C
else if ((I->getOpcode() == Instruction::Add)) {
if (!I->hasOneUse())
return false;
TruncOp = I->user_back();
}
// Check if I is one of step C
if (TruncOp->getOpcode() != Instruction::Trunc)
return false;
if (Instruction *Opnd = dyn_cast<Instruction>(TruncOp->getOperand(0))) {
if (TruncOp->getOpcode() != Instruction::Trunc ||
Opnd->getOpcode() != Instruction::Add || !Opnd->hasNUses(1))
return false;
// Check each operand to the 'add'
unsigned cnt = 0;
for (Value *V : Opnd->operands()) {
if (const Instruction *AddOpnd = dyn_cast<const Instruction>(V)) {
if (AddOpnd->getOpcode() != Instruction::ZExt &&
AddOpnd->getOpcode() != Instruction::SExt)
break;
if (!AddOpnd->getType()->isIntegerTy(32))
break;
if ( AddOpnd->getOperand(0)->getType() != TruncOp->getType() ||
!AddOpnd->hasNUses(1))
break;
}
cnt++;
}
if (cnt == Opnd->getNumOperands()) {
if (OrigType)
*OrigType = TruncOp->getType();
return true;
}
}
return false;
}
static MemAccessInfo calculateMemAccessInfo(Instruction *I,
Type *VectorTy,
LoopVectorizationLegality *Legal,
ScalarEvolution *SE) {
const DataLayout &DL = I->getModule()->getDataLayout();
// Get pointer operand
Value *Ptr = nullptr;
if (auto *LI = dyn_cast<LoadInst>(I))
Ptr = LI->getPointerOperand();
if (auto *SI = dyn_cast<StoreInst>(I))
Ptr = SI->getPointerOperand();
assert (Ptr && "Could not get pointer operand from instruction");
// Check for uniform access (scalar load + splat)
if (Legal->isUniform(Ptr))
return MemAccessInfo::getUniformInfo();
// Get whether it is a predicated memory operation
bool IsMasked = Legal->isMaskRequired(I);
// Try to find the stride of the pointer expression
if (auto *SAR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(Ptr))) {
const SCEV *StepRecurrence = SAR->getStepRecurrence(*SE);
if (auto *StrideV = dyn_cast<SCEVConstant>(StepRecurrence)) {
// Get the element size
unsigned VectorElementSize =
DL.getTypeStoreSize(VectorTy) / VectorTy->getVectorNumElements();
// Normalize Stride from bytes to number of elements
int Stride =
StrideV->getValue()->getSExtValue() / ((int64_t)VectorElementSize);
return MemAccessInfo::getStridedInfo(Stride, Stride < 0, IsMasked);
} else {
// Unknown stride is a subset of gather/scatter
return MemAccessInfo::getNonStridedInfo(StepRecurrence->getType(),
IsMasked);
}
}
// If this is a scatter operation try to find the type of the offset,
// if applicable, e.g. A[i] = B[C[i]]
// ^^^^ get type of C[i]
Type *IdxTy = nullptr;
bool IsSigned = true;
if (auto *Gep = dyn_cast<GetElementPtrInst>(Ptr)) {
for (unsigned Op=0; Op < Gep->getNumOperands(); ++Op) {
Value *Opnd = Gep->getOperand(Op);
if (Legal->isUniform(Opnd)) {
continue;
}
// If there are multiple non-loop invariant indices
// in this GEP, fall back to the worst case below.
if (IdxTy != nullptr) {
IdxTy = nullptr;
break;
}
// If type is promoted, see if we can use smaller type
IdxTy = Opnd->getType();
if (auto *Ext = dyn_cast<CastInst>(Opnd)) {
if (Ext->isIntegerCast())
IdxTy = Ext->getSrcTy();
if (isa<ZExtInst>(Ext))
IsSigned = false;
}
}
}
// Worst case scenario, assume pointer size
if (!IdxTy)
IdxTy = DL.getIntPtrType(Ptr->getType());
return MemAccessInfo::getNonStridedInfo(IdxTy, IsMasked, IsSigned);
}
LoopVectorizationCostModel::VectorizationCostTy
LoopVectorizationCostModel::getInstructionCost(Instruction *I,
VectorizationFactor VF) {
// If we know that this instruction will remain uniform, check the cost of
// the scalar version.
if (Legal->isUniformAfterVectorization(I))
VF.Width = 1;
Type *VectorTy;
unsigned C = getInstructionCost(I, VF, VectorTy);
bool TypeNotScalarized =
VF.Width > 1 && !VectorTy->isVoidTy() &&
TTI.getNumberOfParts(VectorTy) < VF.Width;
return VectorizationCostTy(C, TypeNotScalarized);
}
unsigned LoopVectorizationCostModel::getInstructionCost(Instruction *I,
VectorizationFactor VF,
Type *&VectorTy) {
Type *RetTy = I->getType();
if (VF.Width > 1 && MinBWs.count(I))
RetTy = IntegerType::get(RetTy->getContext(), MinBWs[I]);
VectorTy = ToVectorTy(RetTy, VF);
auto SE = PSE.getSE();
// TODO: We need to estimate the cost of intrinsic calls.
switch (I->getOpcode()) {
case Instruction::GetElementPtr:
// We mark this instruction as zero-cost because the cost of GEPs in
// vectorized code depends on whether the corresponding memory instruction
// is scalarized or not. Therefore, we handle GEPs with the memory
// instruction cost.
return 0;
case Instruction::Br: {
return TTI.getCFInstrCost(I->getOpcode());
}
case Instruction::PHI: {
auto *Phi = cast<PHINode>(I);
// First-order recurrences are replaced by vector shuffles inside the loop.
// TODO: Does getShuffleCost need special handling for scalable vectors?
if (VF.Width > 1 && Legal->isFirstOrderRecurrence(Phi))
return TTI.getShuffleCost(TargetTransformInfo::SK_ExtractSubvector,
VectorTy, VF.Width - 1, VectorTy);
// TODO: IF-converted IFs become selects.
return 0;
}
case Instruction::Add:
case Instruction::FAdd:
case Instruction::Sub:
case Instruction::FSub:
case Instruction::Mul:
case Instruction::FMul:
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::FDiv:
case Instruction::URem:
case Instruction::SRem:
case Instruction::FRem:
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
case Instruction::And:
case Instruction::Or:
case Instruction::Xor: {
// Since we will replace the stride by 1 the multiplication should go away.
if (I->getOpcode() == Instruction::Mul && isStrideMul(I, Legal))
return 0;
// Certain instructions can be cheaper to vectorize if they have a constant
// second vector operand. One example of this are shifts on x86.
TargetTransformInfo::OperandValueKind Op1VK =
TargetTransformInfo::OK_AnyValue;
TargetTransformInfo::OperandValueKind Op2VK =
TargetTransformInfo::OK_AnyValue;
TargetTransformInfo::OperandValueProperties Op1VP =
TargetTransformInfo::OP_None;
TargetTransformInfo::OperandValueProperties Op2VP =
TargetTransformInfo::OP_None;
Value *Op2 = I->getOperand(1);
// Check for a splat of a constant or for a non uniform vector of constants.
if (isa<ConstantInt>(Op2)) {
ConstantInt *CInt = cast<ConstantInt>(Op2);
if (CInt && CInt->getValue().isPowerOf2())
Op2VP = TargetTransformInfo::OP_PowerOf2;
Op2VK = TargetTransformInfo::OK_UniformConstantValue;
} else if (isa<ConstantVector>(Op2) || isa<ConstantDataVector>(Op2)) {
Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
Constant *SplatValue = cast<Constant>(Op2)->getSplatValue();
if (SplatValue) {
ConstantInt *CInt = dyn_cast<ConstantInt>(SplatValue);
if (CInt && CInt->getValue().isPowerOf2())
Op2VP = TargetTransformInfo::OP_PowerOf2;
Op2VK = TargetTransformInfo::OK_UniformConstantValue;
}
}
// Note: When we find a s/zext_to_i32->add->trunc_to_origtype
// chain, we ask the target if it has an add for the original
// type. This is not allowed in C, so the target should ensure
// that the instruction does the sign/zero conversion in 'int'.
Type *OrigType = nullptr;
if (isPartOfPromotedAdd(I, &OrigType))
VectorTy = VectorType::get(OrigType, VF.Width, !VF.isFixed);
return TTI.getArithmeticInstrCost(I->getOpcode(), VectorTy, Op1VK, Op2VK,
Op1VP, Op2VP);
}
case Instruction::Select: {
SelectInst *SI = cast<SelectInst>(I);
const SCEV *CondSCEV = SE->getSCEV(SI->getCondition());
bool ScalarCond = (SE->isLoopInvariant(CondSCEV, TheLoop));
Type *CondTy = SI->getCondition()->getType();
if (!ScalarCond)
CondTy = VectorType::get(CondTy, VF.Width, !VF.isFixed);
return TTI.getCmpSelInstrCost(I->getOpcode(), VectorTy, CondTy);
}
case Instruction::ICmp:
case Instruction::FCmp: {
Type *ValTy = I->getOperand(0)->getType();
Instruction *Op0AsInstruction = dyn_cast<Instruction>(I->getOperand(0));
auto It = MinBWs.find(Op0AsInstruction);
if (VF.Width > 1 && It != MinBWs.end())
ValTy = IntegerType::get(ValTy->getContext(), It->second);
VectorTy = ToVectorTy(ValTy, VF);
return TTI.getCmpSelInstrCost(I->getOpcode(), VectorTy);
}
case Instruction::Store:
case Instruction::Load: {
StoreInst *SI = dyn_cast<StoreInst>(I);
LoadInst *LI = dyn_cast<LoadInst>(I);
Type *ValTy = (SI ? SI->getValueOperand()->getType() : LI->getType());
VectorTy = ToVectorTy(ValTy, VF);
unsigned Alignment = SI ? SI->getAlignment() : LI->getAlignment();
unsigned AS =
SI ? SI->getPointerAddressSpace() : LI->getPointerAddressSpace();
Value *Ptr = SI ? SI->getPointerOperand() : LI->getPointerOperand();
// We add the cost of address computation here instead of with the gep
// instruction because only here we know whether the operation is
// scalarized.
if (VF.Width == 1)
return TTI.getAddressComputationCost(VectorTy) +
TTI.getMemoryOpCost(I->getOpcode(), VectorTy, Alignment, AS);
if (LI && Legal->isUniform(Ptr)) {
// Scalar load + broadcast
unsigned Cost = TTI.getAddressComputationCost(ValTy->getScalarType());
Cost += TTI.getMemoryOpCost(I->getOpcode(), ValTy->getScalarType(),
Alignment, AS);
return Cost +
TTI.getShuffleCost(TargetTransformInfo::SK_Broadcast, ValTy);
}
// For an interleaved access, calculate the total cost of the whole
// interleave group.
if (Legal->isAccessInterleaved(I)) {
auto Group = Legal->getInterleavedAccessGroup(I);
assert(Group && "Fail to get an interleaved access group.");
// Only calculate the cost once at the insert position.
if (Group->getInsertPos() != I)
return 0;
unsigned InterleaveFactor = Group->getFactor();
Type *WideVecTy =
VectorType::get(VectorTy->getVectorElementType(),
VectorTy->getVectorNumElements() * InterleaveFactor,
!VF.isFixed);
// Holds the indices of existing members in an interleaved load group.
// An interleaved store group doesn't need this as it doesn't allow gaps.
SmallVector<unsigned, 4> Indices;
if (LI) {
for (unsigned i = 0; i < InterleaveFactor; i++)
if (Group->getMember(i))
Indices.push_back(i);
}
// Calculate the cost of the whole interleaved group.
unsigned Cost = TTI.getInterleavedMemoryOpCost(
I->getOpcode(), WideVecTy, Group->getFactor(), Indices,
Group->getAlignment(), AS);
if (Group->isReverse())
Cost +=
Group->getNumMembers() *
TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, 0);
// FIXME: The interleaved load group with a huge gap could be even more
// expensive than scalar operations. Then we could ignore such group and
// use scalar operations instead.
return Cost;
}
const DataLayout &DL = I->getModule()->getDataLayout();
unsigned ScalarAllocatedSize = DL.getTypeAllocSize(ValTy);
unsigned VectorElementSize = DL.getTypeStoreSize(VectorTy) / VF.Width;
// Get information about vector memory access
MemAccessInfo MAI = calculateMemAccessInfo(I, VectorTy, Legal, SE);
// If there are no vector memory operations to support the stride,
// get the cost for scalarizing the operation.
if (!TTI.hasVectorMemoryOp(I->getOpcode(), VectorTy, MAI) ||
ScalarAllocatedSize != VectorElementSize) {
// Get cost of scalarizing
// bool IsComplexComputation =
// isLikelyComplexAddressComputation(Ptr, Legal, SE, TheLoop);
unsigned Cost = 0;
// The cost of extracting from the value vector and pointer vector.
Type *PtrTy = ToVectorTy(Ptr->getType(), VF);
for (unsigned i = 0; i < VF.Width; ++i) {
// The cost of extracting the pointer operand.
Cost += TTI.getVectorInstrCost(Instruction::ExtractElement, PtrTy, i);
// In case of STORE, the cost of ExtractElement from the vector.
// In case of LOAD, the cost of InsertElement into the returned
// vector.
Cost += TTI.getVectorInstrCost(SI ? Instruction::ExtractElement
: Instruction::InsertElement,
VectorTy, i);
}
// The cost of the scalar loads/stores.
/* TODO: Replace this with community code?
Cost += VF.Width *
TTI.getAddressComputationCost(PtrTy, IsComplexComputation);
*/
Cost += VF.Width *
TTI.getMemoryOpCost(I->getOpcode(), ValTy->getScalarType(),
Alignment, AS);
return Cost;
}
unsigned Cost = TTI.getAddressComputationCost(VectorTy);
Cost += TTI.getVectorMemoryOpCost(I->getOpcode(), VectorTy, Ptr,
Alignment, AS, MAI, I);
if (MAI.isStrided() && MAI.isReversed())
Cost +=
TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, 0);
else if (MAI.isUniform())
Cost += TTI.getShuffleCost(TargetTransformInfo::SK_Broadcast,
VectorTy, 0);
return Cost;
}
case Instruction::ZExt:
case Instruction::SExt:
case Instruction::FPToUI:
case Instruction::FPToSI:
case Instruction::FPExt:
case Instruction::PtrToInt:
case Instruction::IntToPtr:
case Instruction::SIToFP:
case Instruction::UIToFP:
case Instruction::Trunc:
case Instruction::FPTrunc:
case Instruction::BitCast: {
// We optimize the truncation of induction variable.
// The cost of these is the same as the scalar operation.
if (I->getOpcode() == Instruction::Trunc &&
Legal->isInductionVariable(I->getOperand(0)))
return TTI.getCastInstrCost(I->getOpcode(), I->getType(),
I->getOperand(0)->getType());
// TODO: determine if still useful, deleting isPartOfPromotedAdd if not
// // Don't count these
// if (isPartOfPromotedAdd(I, nullptr))
// return 0;
//
// Type *SrcVecTy = ToVectorTy(I->getOperand(0)->getType(), VF);
Type *SrcScalarTy = I->getOperand(0)->getType();
Type *SrcVecTy = ToVectorTy(SrcScalarTy, VF);
if (VF.Width > 1 && MinBWs.count(I)) {
// This cast is going to be shrunk. This may remove the cast or it might
// turn it into slightly different cast. For example, if MinBW == 16,
// "zext i8 %1 to i32" becomes "zext i8 %1 to i16".
//
// Calculate the modified src and dest types.
Type *MinVecTy = VectorTy;
if (I->getOpcode() == Instruction::Trunc) {
SrcVecTy = smallestIntegerVectorType(SrcVecTy, MinVecTy);
VectorTy =
largestIntegerVectorType(ToVectorTy(I->getType(), VF), MinVecTy);
} else if (I->getOpcode() == Instruction::ZExt ||
I->getOpcode() == Instruction::SExt) {
SrcVecTy = largestIntegerVectorType(SrcVecTy, MinVecTy);
VectorTy =
smallestIntegerVectorType(ToVectorTy(I->getType(), VF), MinVecTy);
}
}
return TTI.getCastInstrCost(I->getOpcode(), VectorTy, SrcVecTy);
}
case Instruction::Call: {
bool NeedToScalarize;
CallInst *CI = cast<CallInst>(I);
unsigned CallCost =
getVectorCallCost(CI, VF, TTI, TLI, *Legal, NeedToScalarize);
if (getVectorIntrinsicIDForCall(CI, TLI))
return std::min(CallCost, getVectorIntrinsicCost(CI, VF.Width, TTI, TLI));
return CallCost;
}
default: {
// We are scalarizing the instruction. Return the cost of the scalar
// instruction, plus the cost of insert and extract into vector
// elements, times the vector width.
unsigned Cost = 0;
if (!RetTy->isVoidTy() && VF.Width != 1) {
unsigned InsCost =
TTI.getVectorInstrCost(Instruction::InsertElement,
VectorTy);
unsigned ExtCost =
TTI.getVectorInstrCost(Instruction::ExtractElement,
VectorTy);
// The cost of inserting the results plus extracting each one of the
// operands.
Cost += VF.Width * (InsCost + ExtCost * I->getNumOperands());
}
// The cost of executing VF copies of the scalar instruction. This opcode
// is unknown. Assume that it is the same as 'mul'.
Cost += VF.Width * TTI.getArithmeticInstrCost(Instruction::Mul, VectorTy);
return Cost;
}
} // end of switch.
}
char SVELoopVectorize::ID = 0;
static const char lv_name[] = "SVE Loop Vectorization";
INITIALIZE_PASS_BEGIN(SVELoopVectorize, LV_NAME, lv_name, false, false)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(BasicAAWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
INITIALIZE_PASS_DEPENDENCY(LoopAccessLegacyAnalysis)
INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
INITIALIZE_PASS_END(SVELoopVectorize, LV_NAME, lv_name, false, false)
namespace llvm {
Pass *createSVELoopVectorizePass(bool NoUnrolling, bool AlwaysVectorize) {
return new SVELoopVectorize(NoUnrolling, AlwaysVectorize);
}
}
bool LoopVectorizationCostModel::isConsecutiveLoadOrStore(Instruction *Inst) {
// Check for a store.
if (StoreInst *ST = dyn_cast<StoreInst>(Inst))
return Legal->isConsecutivePtr(ST->getPointerOperand()) != 0;
// Check for a load.
if (LoadInst *LI = dyn_cast<LoadInst>(Inst))
return Legal->isConsecutivePtr(LI->getPointerOperand()) != 0;
return false;
}
void LoopVectorizationCostModel::collectValuesToIgnore() {
// Ignore ephemeral values.
CodeMetrics::collectEphemeralValues(TheLoop, AC, ValuesToIgnore);
// Ignore type-promoting instructions we identified during reduction
// detection.
for (auto &Reduction : *Legal->getReductionVars()) {
RecurrenceDescriptor &RedDes = Reduction.second;
SmallPtrSetImpl<Instruction *> &Casts = RedDes.getCastInsts();
VecValuesToIgnore.insert(Casts.begin(), Casts.end());
}
// Ignore induction phis that are only used in either GetElementPtr or ICmp
// instruction to exit loop. Induction variables usually have large types and
// can have big impact when estimating register usage.
// This is for when VF > 1.
for (auto &Induction : *Legal->getInductionVars()) {
auto *PN = Induction.first;
auto *UpdateV = PN->getIncomingValueForBlock(TheLoop->getLoopLatch());
// Check that the PHI is only used by the induction increment (UpdateV) or
// by GEPs. Then check that UpdateV is only used by a compare instruction or
// the loop header PHI.
// FIXME: Need precise def-use analysis to determine if this instruction
// variable will be vectorized.
if (std::all_of(PN->user_begin(), PN->user_end(),
[&](const User *U) -> bool {
return U == UpdateV || isa<GetElementPtrInst>(U);
}) &&
std::all_of(UpdateV->user_begin(), UpdateV->user_end(),
[&](const User *U) -> bool {
return U == PN || isa<ICmpInst>(U);
})) {
VecValuesToIgnore.insert(PN);
VecValuesToIgnore.insert(UpdateV);
}
}
// Ignore instructions that will not be vectorized.
// This is for when VF > 1.
for (auto bb = TheLoop->block_begin(), be = TheLoop->block_end(); bb != be;
++bb) {
for (auto &Inst : **bb) {
switch (Inst.getOpcode())
case Instruction::GetElementPtr: {
// Ignore GEP if its last operand is an induction variable so that it is
// a consecutive load/store and won't be vectorized as scatter/gather
// pattern.
GetElementPtrInst *Gep = cast<GetElementPtrInst>(&Inst);
unsigned NumOperands = Gep->getNumOperands();
unsigned InductionOperand = getGEPInductionOperand(Gep);
bool GepToIgnore = true;
// Check that all of the gep indices are uniform except for the
// induction operand.
for (unsigned i = 0; i != NumOperands; ++i) {
if (i != InductionOperand &&
!PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)),
TheLoop)) {
GepToIgnore = false;
break;
}
}
if (GepToIgnore)
VecValuesToIgnore.insert(&Inst);
break;
}
}
}
}
void InnerLoopUnroller::scalarizeInstruction(Instruction *Instr,
bool IfPredicateStore) {
assert(!Instr->getType()->isAggregateType() && "Can't handle vectors");
// Holds vector parameters or scalars, in case of uniform vals.
SmallVector<VectorParts, 4> Params;
setDebugLocFromInst(Builder, Instr);
// Find all of the vectorized parameters.
for (unsigned op = 0, e = Instr->getNumOperands(); op != e; ++op) {
Value *SrcOp = Instr->getOperand(op);
// If we are accessing the old induction variable, use the new one.
if (SrcOp == OldInduction) {
Params.push_back(getVectorValue(SrcOp));
continue;
}
// Try using previously calculated values.
Instruction *SrcInst = dyn_cast<Instruction>(SrcOp);
// If the src is an instruction that appeared earlier in the basic block
// then it should already be vectorized.
if (SrcInst && OrigLoop->contains(SrcInst)) {
assert(WidenMap.has(SrcInst) && "Source operand is unavailable");
// The parameter is a vector value from earlier.
Params.push_back(WidenMap.get(SrcInst));
} else {
// The parameter is a scalar from outside the loop. Maybe even a constant.
VectorParts Scalars;
Scalars.append(UF, SrcOp);
Params.push_back(Scalars);
}
}
assert(Params.size() == Instr->getNumOperands() &&
"Invalid number of operands");
// Does this instruction return a value ?
bool IsVoidRetTy = Instr->getType()->isVoidTy();
Value *UndefVec = IsVoidRetTy ? nullptr : UndefValue::get(Instr->getType());
// Create a new entry in the WidenMap and initialize it to Undef or Null.
VectorParts &VecResults = WidenMap.splat(Instr, UndefVec);
VectorParts Cond;
if (IfPredicateStore) {
assert(Instr->getParent()->getSinglePredecessor() &&
"Only support single predecessor blocks");
Cond = createEdgeMask(Instr->getParent()->getSinglePredecessor(),
Instr->getParent());
}
// For each vector unroll 'part':
for (unsigned Part = 0; Part < UF; ++Part) {
// For each scalar that we create:
// Start an "if (pred) a[i] = ..." block.
Value *Cmp = nullptr;
if (IfPredicateStore) {
if (Cond[Part]->getType()->isVectorTy())
Cond[Part] =
Builder.CreateExtractElement(Cond[Part], Builder.getInt32(0));
Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Cond[Part],
ConstantInt::get(Cond[Part]->getType(), 1));
}
Instruction *Cloned = Instr->clone();
if (!IsVoidRetTy)
Cloned->setName(Instr->getName() + ".cloned");
// Replace the operands of the cloned instructions with extracted scalars.
for (unsigned op = 0, e = Instr->getNumOperands(); op != e; ++op) {
Value *Op = Params[op][Part];
Cloned->setOperand(op, Op);
}
// Place the cloned scalar in the new loop.
Builder.Insert(Cloned);
// If we just cloned a new assumption, add it the assumption cache.
if (auto *II = dyn_cast<IntrinsicInst>(Cloned))
if (II->getIntrinsicID() == Intrinsic::assume)
AC->registerAssumption(II);
// If the original scalar returns a value we need to place it in a vector
// so that future users will be able to use it.
if (!IsVoidRetTy)
VecResults[Part] = Cloned;
// End if-block.
if (IfPredicateStore)
PredicatedStores.push_back(std::make_pair(cast<StoreInst>(Cloned), Cmp));
}
}
void InnerLoopUnroller::vectorizeMemoryInstruction(Instruction *Instr) {
assert(!Legal->isMaskRequired(Instr) &&
"Unroller does not support masked operations!");
StoreInst *SI = dyn_cast<StoreInst>(Instr);
bool IfPredicateStore = (SI && Legal->blockNeedsPredication(SI->getParent()));
return scalarizeInstruction(Instr, IfPredicateStore);
}
Value *InnerLoopUnroller::reverseVector(Value *Vec) { return Vec; }
Value *InnerLoopUnroller::getBroadcastInstrs(Value *V) { return V; }
Value *InnerLoopUnroller::getStepVector(Value *Val, Value *Start,
const SCEV *StepSCEV,
Instruction::BinaryOps BinOp) {
const DataLayout &DL = OrigLoop->getHeader()->getModule()->getDataLayout();
SCEVExpander Exp(*PSE.getSE(), DL, "induction");
Value *StepValue = Exp.expandCodeFor(StepSCEV, StepSCEV->getType(),
&*Builder.GetInsertPoint());
return getStepVector(Val, Start, StepValue, BinOp);
}
Value *InnerLoopUnroller::getStepVector(Value *Val, int Start, Value *Step,
Instruction::BinaryOps BinOp) {
// When unrolling and the VF is 1, we only need to add a simple scalar.
Type *Ty = Val->getType()->getScalarType();
return getStepVector(Val, ConstantInt::get(Ty, Start), Step, BinOp);
}
Value *InnerLoopUnroller::getStepVector(Value *Val, Value* Start, Value *Step,
Instruction::BinaryOps BinOp) {
// When unrolling and the VF is 1, we only need to add a simple scalar.
assert(!Val->getType()->isVectorTy() && "Val must be a scalar");
if (Val->getType()->isFloatingPointTy()) {
if (Start->getType()->isIntegerTy())
Start = Builder.CreateUIToFP(Start, Val->getType());
Step = addFastMathFlag(Builder.CreateFMul(Start, Step));
return addFastMathFlag(Builder.CreateBinOp(BinOp, Val, Step, "fpinduction"));
}
return Builder.CreateAdd(Val, Builder.CreateMul(Start, Step), "induction");
}
| [
"graham.hunter@arm.com"
] | graham.hunter@arm.com |
8a1633ff61b7f989c100f1edb57dc50bf785bdad | 82301a80f1937089a7347c6ff8aefab6349e235d | /perfection 382.cpp | cc6860c2bbef0e1baa9bbc9d03403dfc7a6b0771 | [] | no_license | oviebd/My_Uva_Solutions | 334e102d2347999d342846c6be50900c6a713fac | 5d34f2d4b87e4312695b33243413cbea4c634ef6 | refs/heads/master | 2021-04-29T01:07:29.854303 | 2017-01-01T15:44:28 | 2017-01-01T15:44:28 | 77,785,049 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 596 | cpp | #include<stdio.h>
int main()
{
int n,i,j,k,l,m,sum;
printf("PERFECTION OUTPUT\n");
while(scanf("%d",&n)==1)
{
if(n==0)
break;
sum=0;
for(i=1;i<=n/2;i++)
{
if(n%i==0)
sum=sum+i;
printf("%d",sum);
}
if(sum==n)
{
printf("%5d PERFECT\n",n);
}
else if(sum<n)
{
printf("%5d DEFICIENT\n",n);
}
else
{
printf("%5d ABUNDANT\n",n);
}
}
printf("END OF OUTPUT\n");
return 0;
}
| [
"oviework@gmail.com"
] | oviework@gmail.com |
50a7fa6727377fffef8a87950482946d8d999868 | f49af15675a8528de1f7d929e16ded0463cb88e6 | /C++/C++ Advanced/HomeworkExcersises/01PointersAndReferences/04Profit/Company.h | 1a8fa315d08b6c4fe600b3e343da6c70aa7d6f45 | [] | no_license | genadi1980/SoftUni | 0a5e207e0038fb7855fed7cddc088adbf4cec301 | 6562f7e6194c53d1e24b14830f637fea31375286 | refs/heads/master | 2021-01-11T18:57:36.163116 | 2019-05-18T13:37:19 | 2019-05-18T13:37:19 | 79,638,550 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 832 | h | #ifndef COMPANY_H
#include <string>
class Company {
public:
std::string getName() const {
return this->_name;
}
int getId() const {
return this->_id;
}
int getRevenue() const {
return this->_revenue;
}
int getCosts() const {
return this->_costs;
}
private:
std::string _name;
int _id;
int _revenue;
int _costs;
friend std::istream& operator>>(std::istream& stream, Company & company);
};
std::istream& operator>>(std::istream& stream, Company & company) {
char separator;
return stream >> company._name >> company._id >> separator >> company._revenue >> company._costs;
}
std::ostream& operator<<(std::ostream& stream, Company & company) {
return stream << company.getName() << " " << company.getId() << " " << company.getRevenue() << company.getCosts();
}
#define COMPANY_H
#endif // !COMPANY_H
| [
"genadi_georgiev@abv.bg"
] | genadi_georgiev@abv.bg |
20b1988bee9975387bf177b49f18c5e981ba0803 | 62916038bc3650e161c53bc1f9a44df02dca8fe3 | /src/platform_cfg.h | b4b03b10bfb4a71b7be22672c050329fa70a72a3 | [
"Apache-2.0"
] | permissive | git-root/trex-core | 8eb937cdc37ced69f473398876b062736bdcdd37 | 82280f7c87fabed60d83643bd9ec2c79cac34668 | refs/heads/master | 2021-01-18T05:02:45.738002 | 2015-11-09T09:20:28 | 2015-11-09T09:20:28 | 45,956,189 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,986 | h | #ifndef CPLATFORM_CFG_H
#define CPLATFORM_CFG_H
/*
Hanoh Haim
Cisco Systems, Inc.
*/
/*
Copyright (c) 2015-2015 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <yaml-cpp/yaml.h>
#include <stdint.h>
#include <stdio.h>
#include <vector>
#include <string>
#define CONST_NB_MBUF_2_10G (16380/4)
typedef enum { MBUF_64 =0, // per dual port, per NUMA
MBUF_128 =1,
MBUF_256 =2,
MBUF_512 =3,
MBUF_1024 =4,
MBUF_2048 =5,
// per NUMA
TRAFFIC_MBUF_64 =6,
TRAFFIC_MBUF_128 =7,
TRAFFIC_MBUF_256 =8,
TRAFFIC_MBUF_512 =9,
TRAFFIC_MBUF_1024 =10,
TRAFFIC_MBUF_2048 =11,
MBUF_DP_FLOWS =12,
MBUF_GLOBAL_FLOWS =13,
MBUF_SIZE =14
} mbuf_sizes_t;
const std::string * get_mbuf_names(void);
/*
#- port_limit : 2 # this option can limit the number of port of the platform
cpu_mask_offset : 4 # the offset of the cpu affinity
interface_mask : [ "0000:11:00.00", "0000:11:00.01" ] # interface that should be mask and not be considered
scan_only_1g : true
enable_zmq_pub : true # enable publisher for stats data
zmq_pub_port : 4500
telnet_port : 4501 # the telnet port in case it is enable ( with intercative mode )
port_info : # set eh mac addr
- dest_mac : [0x0,0x0,0x0,0x1,0x0,0x00] # port 0
src_mac : [0x0,0x0,0x0,0x1,0x0,0x00]
#for system of 1Gb/sec NIC or VM enable this
port_bandwidth_gb : 10 # port bandwidth 10Gb/sec , for VM put here 1 for XL710 put 40
# memory configuration for 2x10Gb/sec system
memory :
mbuf_64 : 16380
mbuf_128 : 8190
mbuf_256 : 8190
mbuf_512 : 8190
mbuf_1024 : 8190
mbuf_2048 : 2049
traffic_mbuf_128 : 8190
traffic_mbuf_256 : 8190
traffic_mbuf_512 : 8190
traffic_mbuf_1024 : 8190
traffic_mbuf_2048 : 2049
dp_flows : 1048576
global_flows : 10240
*/
struct CMacYamlInfo {
std::vector <uint8_t> m_dest_base;
std::vector <uint8_t> m_src_base;
void Dump(FILE *fd);
void copy_dest(char *p);
void copy_src(char *p);
void dump_mac_vector( std::vector<uint8_t> & v,FILE *fd){
int i;
for (i=0; i<5; i++) {
fprintf(fd,"%02x:",v[i]);
}
fprintf(fd,"%02x\n",v[5]);
}
};
/*
platform :
master_core : 0
latency_core : 5
dual_if :
- socket : 0
threads : [1,2,3,4]
- socket : 1
threads : [16,17,18,16]
*/
struct CPlatformDualIfYamlInfo {
public:
uint32_t m_socket;
std::vector <uint8_t> m_threads;
public:
void Dump(FILE *fd);
};
struct CPlatformCoresYamlInfo {
public:
CPlatformCoresYamlInfo(){
m_is_exists=false;
}
bool m_is_exists;
uint32_t m_master_thread;
uint32_t m_latency_thread;
std::vector <CPlatformDualIfYamlInfo> m_dual_if;
public:
void Dump(FILE *fd);
};
struct CPlatformMemoryYamlInfo {
public:
CPlatformMemoryYamlInfo(){
reset();
}
uint32_t m_mbuf[MBUF_SIZE]; // relative to traffic norm to 2x10G ports
public:
void Dump(FILE *fd);
void reset();
};
struct CPlatformYamlInfo {
public:
CPlatformYamlInfo(){
reset();
}
void reset(){
m_if_mask.clear();
m_mac_info.clear();
m_if_list.clear();
m_info_exist=false;
m_port_limit_exist=false;
m_port_limit=0xffffffff;
m_if_mask_exist=false;
m_enable_zmq_pub_exist=false;
m_enable_zmq_pub=true;
m_zmq_pub_port=4500;
m_telnet_exist=false;
m_telnet_port=4502 ;
m_zmq_rpc_port = 5050;
m_mac_info_exist=false;
m_port_bandwidth_gb = 10;
m_memory.reset();
m_prefix="";
m_limit_memory="" ;
m_thread_per_dual_if=1;
}
bool m_info_exist; /* file exist ?*/
bool m_port_limit_exist;
uint32_t m_port_limit;
bool m_if_mask_exist;
std::vector <std::string> m_if_mask;
std::vector <std::string> m_if_list;
std::string m_prefix;
std::string m_limit_memory;
uint32_t m_thread_per_dual_if;
uint32_t m_port_bandwidth_gb;
bool m_enable_zmq_pub_exist;
bool m_enable_zmq_pub;
uint16_t m_zmq_pub_port;
bool m_telnet_exist;
uint16_t m_telnet_port;
uint16_t m_zmq_rpc_port;
bool m_mac_info_exist;
std::vector <CMacYamlInfo> m_mac_info;
CPlatformMemoryYamlInfo m_memory;
CPlatformCoresYamlInfo m_platform;
public:
std::string get_use_if_comma_seperated();
void Dump(FILE *fd);
int load_from_yaml_file(std::string file_name);
};
#endif
| [
"hhaim@cisco.com"
] | hhaim@cisco.com |
a9fa8d11ec7229be026b4d7ee6d2ece2ef24955f | 63e471c874b46cf89b0c1da86b8c7806a87b1f63 | /source/test.h | 608fdec6943047982d45027562a557df52a91aa8 | [
"BSD-2-Clause"
] | permissive | mattiapenati/gas-framework | b5dd7af8c0789f43a483cb211b415864aa5a98f4 | 77904ce6daf82a6b8650fa9ecea9a53c71aad58e | refs/heads/master | 2021-01-10T07:25:00.467336 | 2012-04-27T12:32:30 | 2012-04-27T12:32:30 | 46,281,503 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,417 | h | /*
* Copyright (c) 2009, Politecnico di Milano
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Milano nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*!
* @file test.h
* @brief A minimal class to write unit test
*/
#ifndef GAS_TEST_H
#define GAS_TEST_H
/*!
* @def GAS_UNIT(TEST)
* @brief An alias for the main of test
*/
#define GAS_UNIT(TEST) \
int main (int argc, char * argv[]) { \
gas::test<TEST>::run(); \
return 0; \
}
#define gas_unit GAS_UNIT
namespace gas {
/*!
* @brief A minimal class to write unit test
* @param Test A class that contain the execution code for the test
*
* To write a unit test is quite simple, first you have to copy the file
* empty.cpp and rename it as you prefer. Give a name at your test (line 33) and
* start to code.
*/
template <typename test_>
class test {
public:
/*!
* @brief Execute the unit test
*/
static void run () {
test_ obj;
obj.execute();
obj.check();
}
};
}
#endif // GAS_TEST_H
| [
"mattia.penati@f5836fa8-9f95-11dd-a874-8d3a81574e67"
] | mattia.penati@f5836fa8-9f95-11dd-a874-8d3a81574e67 |
e6e2cbc9727e71af2d48b8802f0c467cf921f5ec | 3347f654fda9b1f2f7409aeb5eec30f33d340cef | /TetrisAdmin.h | d1c08b684d561cb1e8b4d67acbed564c98244eb0 | [] | no_license | loctran107/Gesture_Controlled_Tetris_Game | b9e52fb1b942a837eb5d6a65157042a28a0a43da | 4abeef0837195c2efe077c59514ead3169a1639d | refs/heads/master | 2022-11-20T05:53:50.949978 | 2020-07-13T20:33:24 | 2020-07-13T20:33:24 | 277,728,047 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 225 | h | #ifndef _TETRISADMIN_H_
#define _TETRISADMIN_H_
#include <cstdlib>
#include "Tetris.h"
class TetrisAdmin {
public:
TetrisAdmin() { } //constructor
void normalMode();
void flexMode();
};
#endif //_TETRISADMIN_H_
| [
"dontr710@gmail.com"
] | dontr710@gmail.com |
e8ff2ac4184e3eddd74ffc3e92367a5f94d7bd2d | f3c8d78b4f8af9a5a0d047fbae32a5c2fca0edab | /Qt/my_old_programm/Bluetooth/src/connectivity/nfc/maemo6/tag_interface.cpp | 85d92957477783b0bfab7b1cf08779c66f698896 | [] | no_license | RinatB2017/mega_GIT | 7ddaa3ff258afee1a89503e42b6719fb57a3cc32 | f322e460a1a5029385843646ead7d6874479861e | refs/heads/master | 2023-09-02T03:44:33.869767 | 2023-08-21T08:20:14 | 2023-08-21T08:20:14 | 97,226,298 | 5 | 2 | null | 2022-12-09T10:31:43 | 2017-07-14T11:17:39 | C++ | UTF-8 | C++ | false | false | 2,726 | cpp | /****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*
* This file was generated by qdbusxml2cpp version 0.7
* Command line was: qdbusxml2cpp -p tag_interface_p.h:tag_interface.cpp com.nokia.nfc.Tag.xml
*
* qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/
#include "tag_interface_p.h"
/*
* Implementation of interface class ComNokiaNfcTagInterface
*/
ComNokiaNfcTagInterface::ComNokiaNfcTagInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
{
}
ComNokiaNfcTagInterface::~ComNokiaNfcTagInterface()
{
}
| [
"tux4096@gmail.com"
] | tux4096@gmail.com |
0af6e2980744681ae51e4138970f847bce62d79f | 6c6318b91229e09b41d637a14c7c4df3f77dede1 | /utils/vk_loader_platform.h | 583c3f3c24d22b96b95f9fd4719fa4d185b63d00 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | hixio-mh/Vulkan-ExtensionLayer | b524abbc2aa2554a66b112d260599ec118c69e44 | 1230d7f8e4c37f76b28c9883125cc88223387861 | refs/heads/master | 2023-07-15T12:33:23.074839 | 2021-08-26T14:57:15 | 2021-08-26T15:23:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 14,316 | h | /*
*
* Copyright (c) 2015-2021 The Khronos Group Inc.
* Copyright (c) 2015-2021 Valve Corporation
* Copyright (c) 2015-2021 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Ian Elliot <ian@lunarg.com>
* Author: Jon Ashburn <jon@lunarg.com>
* Author: Lenny Komow <lenny@lunarg.com>
*
*/
#pragma once
#if defined(_WIN32)
// WinSock2.h must be included *BEFORE* windows.h
#include <WinSock2.h>
#endif // _WIN32
#include "vulkan/vk_platform.h"
// sdk_platform header redefines NOMINMAX
#undef NOMINMAX
#include "vulkan/vk_sdk_platform.h"
#if defined(__linux__) || defined(__APPLE__)
/* Linux-specific common code: */
// Headers:
//#define _GNU_SOURCE 1
// TBD: Are the contents of the following file used?
#include <unistd.h>
// Note: The following file is for dynamic loading:
#include <dlfcn.h>
#include <pthread.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libgen.h>
// VK Library Filenames, Paths, etc.:
#define PATH_SEPARATOR ':'
#define DIRECTORY_SYMBOL '/'
#define VULKAN_DIR "/vulkan/"
#define VULKAN_ICDCONF_DIR "icd.d"
#define VULKAN_ICD_DIR "icd"
#define VULKAN_ELAYERCONF_DIR "explicit_layer.d"
#define VULKAN_ILAYERCONF_DIR "implicit_layer.d"
#define VULKAN_LAYER_DIR "layer"
#define DEFAULT_VK_DRIVERS_INFO ""
#define DEFAULT_VK_ELAYERS_INFO ""
#define DEFAULT_VK_ILAYERS_INFO ""
#define DEFAULT_VK_DRIVERS_PATH ""
#if !defined(DEFAULT_VK_LAYERS_PATH)
#define DEFAULT_VK_LAYERS_PATH ""
#endif
#if !defined(LAYERS_SOURCE_PATH)
#define LAYERS_SOURCE_PATH NULL
#endif
#define LAYERS_PATH_ENV "VK_LAYER_PATH"
#define ENABLED_LAYERS_ENV "VK_INSTANCE_LAYERS"
#define RELATIVE_VK_DRIVERS_INFO VULKAN_DIR VULKAN_ICDCONF_DIR
#define RELATIVE_VK_ELAYERS_INFO VULKAN_DIR VULKAN_ELAYERCONF_DIR
#define RELATIVE_VK_ILAYERS_INFO VULKAN_DIR VULKAN_ILAYERCONF_DIR
// C99:
#define PRINTF_SIZE_T_SPECIFIER "%zu"
// File IO
static inline bool loader_platform_file_exists(const char *path) {
if (access(path, F_OK))
return false;
else
return true;
}
static inline bool loader_platform_is_path_absolute(const char *path) {
if (path[0] == '/')
return true;
else
return false;
}
static inline char *loader_platform_dirname(char *path) { return dirname(path); }
// Dynamic Loading of libraries:
typedef void *loader_platform_dl_handle;
static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) {
// When loading the library, we use RTLD_LAZY so that not all symbols have to be
// resolved at this time (which improves performance). Note that if not all symbols
// can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment
// variable to force all symbols to be resolved here.
return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL);
}
static inline const char *loader_platform_open_library_error(const char *libPath) { return dlerror(); }
static inline void loader_platform_close_library(loader_platform_dl_handle library) { dlclose(library); }
static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
assert(library);
assert(name);
return dlsym(library, name);
}
static inline const char *loader_platform_get_proc_address_error(const char *name) { return dlerror(); }
// Threads:
typedef pthread_t loader_platform_thread;
#define THREAD_LOCAL_DECL __thread
// The once init functionality is not used on Linux
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var)
#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var)
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func)
// Thread IDs:
typedef pthread_t loader_platform_thread_id;
static inline loader_platform_thread_id loader_platform_get_thread_id() { return pthread_self(); }
// Thread mutex:
typedef pthread_mutex_t loader_platform_thread_mutex;
static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_init(pMutex, NULL); }
static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }
static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }
static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_destroy(pMutex); }
typedef pthread_cond_t loader_platform_thread_cond;
static inline void loader_platform_thread_init_cond(loader_platform_thread_cond *pCond) { pthread_cond_init(pCond, NULL); }
static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond *pCond, loader_platform_thread_mutex *pMutex) {
pthread_cond_wait(pCond, pMutex);
}
static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond *pCond) { pthread_cond_broadcast(pCond); }
#define loader_stack_alloc(size) alloca(size)
#elif defined(_WIN32) // defined(__linux__)
/* Windows-specific common code: */
// WinBase.h defines CreateSemaphore and synchapi.h defines CreateEvent
// undefine them to avoid conflicts with VkLayerDispatchTable struct members.
#ifdef CreateSemaphore
#undef CreateSemaphore
#endif
#ifdef CreateEvent
#undef CreateEvent
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <stdbool.h>
#include <shlwapi.h>
#ifdef __cplusplus
#include <iostream>
#include <string>
#endif // __cplusplus
// VK Library Filenames, Paths, etc.:
#define PATH_SEPARATOR ';'
#define DIRECTORY_SYMBOL '\\'
#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE
#define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE"
#define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER
#define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER"
#define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\Drivers"
#define DEFAULT_VK_DRIVERS_PATH ""
#define DEFAULT_VK_ELAYERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\ExplicitLayers"
#define DEFAULT_VK_ILAYERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\ImplicitLayers"
#if !defined(DEFAULT_VK_LAYERS_PATH)
#define DEFAULT_VK_LAYERS_PATH ""
#endif
#if !defined(LAYERS_SOURCE_PATH)
#define LAYERS_SOURCE_PATH NULL
#endif
#define LAYERS_PATH_ENV "VK_LAYER_PATH"
#define ENABLED_LAYERS_ENV "VK_INSTANCE_LAYERS"
#define RELATIVE_VK_DRIVERS_INFO ""
#define RELATIVE_VK_ELAYERS_INFO ""
#define RELATIVE_VK_ILAYERS_INFO ""
#define PRINTF_SIZE_T_SPECIFIER "%Iu"
#if defined(_WIN32)
// Get the key for the plug n play driver registry
// The string returned by this function should NOT be freed
static inline const char *LoaderPnpDriverRegistry() {
BOOL is_wow;
IsWow64Process(GetCurrentProcess(), &is_wow);
return is_wow ? (API_NAME "DriverNameWow") : (API_NAME "DriverName");
}
// Get the key for the plug 'n play explicit layer registry
// The string returned by this function should NOT be freed
static inline const char *LoaderPnpELayerRegistry() {
BOOL is_wow;
IsWow64Process(GetCurrentProcess(), &is_wow);
return is_wow ? (API_NAME "ExplicitLayersWow") : (API_NAME "ExplicitLayers");
}
// Get the key for the plug 'n play implicit layer registry
// The string returned by this function should NOT be freed
static inline const char *LoaderPnpILayerRegistry() {
BOOL is_wow;
IsWow64Process(GetCurrentProcess(), &is_wow);
return is_wow ? (API_NAME "ImplicitLayersWow") : (API_NAME "ImplicitLayers");
}
#endif
// File IO
static bool loader_platform_file_exists(const char *path) {
if ((_access(path, 0)) == -1)
return false;
else
return true;
}
static bool loader_platform_is_path_absolute(const char *path) {
if (!path || !*path) {
return false;
}
if (*path == DIRECTORY_SYMBOL || path[1] == ':') {
return true;
}
return false;
}
// WIN32 runtime doesn't have dirname().
static inline char *loader_platform_dirname(char *path) {
char *current, *next;
// TODO/TBD: Do we need to deal with the Windows's ":" character?
for (current = path; *current != '\0'; current = next) {
next = strchr(current, DIRECTORY_SYMBOL);
if (next == NULL) {
if (current != path) *(current - 1) = '\0';
return path;
} else {
// Point one character past the DIRECTORY_SYMBOL:
next++;
}
}
return path;
}
// WIN32 runtime doesn't have basename().
// Microsoft also doesn't have basename(). Paths are different on Windows, and
// so this is just a temporary solution in order to get us compiling, so that we
// can test some scenarios, and develop the correct solution for Windows.
// TODO: Develop a better, permanent solution for Windows, to replace this
// temporary code:
static char *loader_platform_basename(char *pathname) {
char *current, *next;
// TODO/TBD: Do we need to deal with the Windows's ":" character?
for (current = pathname; *current != '\0'; current = next) {
next = strchr(current, DIRECTORY_SYMBOL);
if (next == NULL) {
// No more DIRECTORY_SYMBOL's so return p:
return current;
} else {
// Point one character past the DIRECTORY_SYMBOL:
next++;
}
}
// We shouldn't get to here, but this makes the compiler happy:
return current;
}
// Dynamic Loading:
typedef HMODULE loader_platform_dl_handle;
static loader_platform_dl_handle loader_platform_open_library(const char *lib_path) {
// Try loading the library the original way first.
loader_platform_dl_handle lib_handle = LoadLibrary(lib_path);
if (lib_handle == NULL && GetLastError() == ERROR_MOD_NOT_FOUND) {
// If that failed, then try loading it with broader search folders.
lib_handle = LoadLibraryEx(lib_path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
}
return lib_handle;
}
static char *loader_platform_open_library_error(const char *libPath) {
static char errorMsg[164];
(void)snprintf(errorMsg, 163, "Failed to open dynamic library \"%s\" with error %lu", libPath, GetLastError());
return errorMsg;
}
static void loader_platform_close_library(loader_platform_dl_handle library) { FreeLibrary(library); }
static void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
assert(library);
assert(name);
return (void *)GetProcAddress(library, name);
}
static char *loader_platform_get_proc_address_error(const char *name) {
static char errorMsg[120];
(void)snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name);
return errorMsg;
}
// Threads:
typedef HANDLE loader_platform_thread;
#define THREAD_LOCAL_DECL __declspec(thread)
// The once init functionality is not used when building a DLL on Windows. This is because there is no way to clean up the
// resources allocated by anything allocated by once init. This isn't a problem for static libraries, but it is for dynamic
// ones. When building a DLL, we use DllMain() instead to allow properly cleaning up resources.
#if defined(LOADER_DYNAMIC_LIB)
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var)
#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var)
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func)
#else
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT;
#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) INIT_ONCE var;
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func)
static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) {
void (*func)(void) = (void (*)(void))Parameter;
func();
return TRUE;
}
static void loader_platform_thread_once_fn(void *ctl, void (*func)(void)) {
assert(func != NULL);
assert(ctl != NULL);
InitOnceExecuteOnce((PINIT_ONCE)ctl, InitFuncWrapper, (void *)func, NULL);
}
#endif
// Thread IDs:
typedef DWORD loader_platform_thread_id;
static loader_platform_thread_id loader_platform_get_thread_id() { return GetCurrentThreadId(); }
// Thread mutex:
typedef CRITICAL_SECTION loader_platform_thread_mutex;
static void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { InitializeCriticalSection(pMutex); }
static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { EnterCriticalSection(pMutex); }
static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { LeaveCriticalSection(pMutex); }
static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { DeleteCriticalSection(pMutex); }
typedef CONDITION_VARIABLE loader_platform_thread_cond;
static void loader_platform_thread_init_cond(loader_platform_thread_cond *pCond) { InitializeConditionVariable(pCond); }
static void loader_platform_thread_cond_wait(loader_platform_thread_cond *pCond, loader_platform_thread_mutex *pMutex) {
SleepConditionVariableCS(pCond, pMutex, INFINITE);
}
static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond *pCond) { WakeAllConditionVariable(pCond); }
#define loader_stack_alloc(size) _alloca(size)
#else // defined(_WIN32)
#error The "loader_platform.h" file must be modified for this OS.
// NOTE: In order to support another OS, an #elif needs to be added (above the
// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the
// contents of this file must be created.
// NOTE: Other OS-specific changes are also needed for this OS. Search for
// files with "WIN32" in it, as a quick way to find files that must be changed.
#endif // defined(_WIN32)
// returns true if the given string appears to be a relative or absolute
// path, as opposed to a bare filename.
static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; }
| [
"jeremyg@lunarg.com"
] | jeremyg@lunarg.com |
32f10ce3fea4c50c99e6fc51041241660946db0c | 05048aa617d2a712a4fafcfcf2ad33e267a810ea | /Lab/Lab 8/Fibonacci/main.cpp | 565edbb55d0c72305c13e4be9be2f12882c072b7 | [] | no_license | AyinDJ/HeXiaojun_46090 | b56ba1da9e7cff4ae770c1d70a7242eec2ae9b81 | 1c3dd473cb7e8dae9fe604d5ff2194a9fe644c40 | refs/heads/master | 2016-09-06T19:56:14.035606 | 2015-07-17T00:21:48 | 2015-07-17T00:21:48 | 38,069,622 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,081 | cpp | /*
* File: main.cpp
* Author: Xiaojun He
* Purpose: Generate the Fibonacci Sequence
*
* Created on July 2, 2015, 11:06 AM
*/
#include <iostream>
#include <iomanip>
using namespace std;
//User Libraries
//Global Constants
//Function Prototypes
//Execution Begins Here!
int main(int argc, char** argv) {
//Declare and initialize members of the sequence
unsigned short fi=1, fip1=1, fip2;
unsigned char terms=10;
//Print the initial conditions
cout<<"The number of terms in Fibonacci sequence"<<
"to display is "<<terms<<endl;
cout<<"Term "<<1<<"in the sequence = "<<fi<<endl;
cout<<"Term "<<2<<"in the sequence = "<<fip1<<endl;
//Loop and show terms as you generate
for(unsigned char term=3;term<=terms;term++){
//Calculate the next term in the sequence
fip2=fi+fip1;
//Output the current term
cout<<"Term "<<static_cast<int>(term)<<" in the sequence = "<<fip2<<endl;
//No shift
fi=fip1;
fip1=fip2;
}
//Exit stage right
return 0;
}
| [
"amazinghxj@gmail.com"
] | amazinghxj@gmail.com |
9c4ad7225e6ca2741034ef87a21ab6c657cccb40 | fd81ece5b7ac96e4c2456a8633204d95a2ecb980 | /ysclass/src/ystextresource.h | d281779c6b80f3b8a067fb7be8d4f817f3084501 | [] | no_license | PeterZs/MCG03 | 5607659ea8299edd0012aeb56bc7f41315eee7f2 | 1620f130852b89bd6f202ba215b608c7520689ea | refs/heads/master | 2021-01-12T22:18:52.335411 | 2015-04-04T02:19:24 | 2015-04-04T02:19:24 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,864 | h | /* ////////////////////////////////////////////////////////////
YS Class Library
Copyright (c) 2014 Soji Yamakawa. All rights reserved.
YS Class Library is an open-source class-library project since 1999.
It has been used and battle-tested in commercial, research, and free programs.
Please visit the following URL for more details.
http://www.ysflight.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: ystextresource.h
//////////////////////////////////////////////////////////// */
#ifndef YSTEXTRESOURCE_IS_INCLUDED
#define YSTEXTRESOURCE_IS_INCLUDED
/* { */
#include "ysstring.h"
#include "ysproperty.h"
#include "ysbinarytree.h"
class YsTextResource
{
private:
YsString label;
YsColor fgCol,bgCol;
class YsTextResourceBinaryTree *tree;
// I want to write YsStringBinaryTree directly here, but if I do so,
// Visual C++ 2008 gives a warning that totally doesn't make sense:
// ysbinarytree.h(371) : warning C4505: 'YsStringBinaryTree<KEYTYPE,ASSOCTYPE>::Compare' :
// unreferenced local function has been removed
// Compare is a template function and if it is not used, it is deleted. Period.
// I say Visual Studio 2008 is wrongfully accusing this function.
public:
YsTextResource();
virtual ~YsTextResource();
void Initialize(void);
YSRESULT LoadFile(const char fn[]);
YSRESULT LoadFile(FILE *fp);
protected:
YSRESULT SendCommand(const YsString &cmd);
YSRESULT SendDollarCommand(const YsString &cmd);
YSRESULT SendDictCommand(const YsString &cmd);
public:
const wchar_t *FindWString(const char key[]);
};
/* } */
#endif
| [
"lijing070769@hotmail.com"
] | lijing070769@hotmail.com |
b0cb7c53350f326449c252cd7b5902ab15081e64 | ac372e2fdc9352414169b4791e58f43ec56b8922 | /Export/linux/obj/src/lime/graphics/opengl/ext/NV_coverage_sample.cpp | 321bd56069d9fe04ad7780886ca0e6e283847c75 | [] | no_license | JavaDeva/HAXE_TPE | 4c7023811b153061038fe0effe913f055f531e22 | a201e718b73658bff943c268b097a86f858d3817 | refs/heads/master | 2022-08-15T21:33:14.010205 | 2020-05-28T15:34:32 | 2020-05-28T15:34:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | true | 7,710 | cpp | // Generated by Haxe 4.1.1
#include <hxcpp.h>
#ifndef INCLUDED_lime_graphics_opengl_ext_NV_coverage_sample
#include <lime/graphics/opengl/ext/NV_coverage_sample.h>
#endif
HX_DEFINE_STACK_FRAME(_hx_pos_d197f49e97430958_4_new,"lime.graphics.opengl.ext.NV_coverage_sample","new",0x08bce1be,"lime.graphics.opengl.ext.NV_coverage_sample.new","lime/graphics/opengl/ext/NV_coverage_sample.hx",4,0xb353c790)
namespace lime{
namespace graphics{
namespace opengl{
namespace ext{
void NV_coverage_sample_obj::__construct(){
HX_STACKFRAME(&_hx_pos_d197f49e97430958_4_new)
HXLINE( 14) this->COVERAGE_BUFFER_BIT_NV = 32768;
HXLINE( 13) this->COVERAGE_AUTOMATIC_NV = 36567;
HXLINE( 12) this->COVERAGE_EDGE_FRAGMENTS_NV = 36566;
HXLINE( 11) this->COVERAGE_ALL_FRAGMENTS_NV = 36565;
HXLINE( 10) this->COVERAGE_SAMPLES_NV = 36564;
HXLINE( 9) this->COVERAGE_BUFFERS_NV = 36563;
HXLINE( 8) this->COVERAGE_ATTACHMENT_NV = 36562;
HXLINE( 7) this->COVERAGE_COMPONENT4_NV = 36561;
HXLINE( 6) this->COVERAGE_COMPONENT_NV = 36560;
}
Dynamic NV_coverage_sample_obj::__CreateEmpty() { return new NV_coverage_sample_obj; }
void *NV_coverage_sample_obj::_hx_vtable = 0;
Dynamic NV_coverage_sample_obj::__Create(::hx::DynamicArray inArgs)
{
::hx::ObjectPtr< NV_coverage_sample_obj > _hx_result = new NV_coverage_sample_obj();
_hx_result->__construct();
return _hx_result;
}
bool NV_coverage_sample_obj::_hx_isInstanceOf(int inClassId) {
return inClassId==(int)0x00000001 || inClassId==(int)0x3cf51454;
}
NV_coverage_sample_obj::NV_coverage_sample_obj()
{
}
::hx::Val NV_coverage_sample_obj::__Field(const ::String &inName,::hx::PropertyAccess inCallProp)
{
switch(inName.length) {
case 19:
if (HX_FIELD_EQ(inName,"COVERAGE_BUFFERS_NV") ) { return ::hx::Val( COVERAGE_BUFFERS_NV ); }
if (HX_FIELD_EQ(inName,"COVERAGE_SAMPLES_NV") ) { return ::hx::Val( COVERAGE_SAMPLES_NV ); }
break;
case 21:
if (HX_FIELD_EQ(inName,"COVERAGE_COMPONENT_NV") ) { return ::hx::Val( COVERAGE_COMPONENT_NV ); }
if (HX_FIELD_EQ(inName,"COVERAGE_AUTOMATIC_NV") ) { return ::hx::Val( COVERAGE_AUTOMATIC_NV ); }
break;
case 22:
if (HX_FIELD_EQ(inName,"COVERAGE_COMPONENT4_NV") ) { return ::hx::Val( COVERAGE_COMPONENT4_NV ); }
if (HX_FIELD_EQ(inName,"COVERAGE_ATTACHMENT_NV") ) { return ::hx::Val( COVERAGE_ATTACHMENT_NV ); }
if (HX_FIELD_EQ(inName,"COVERAGE_BUFFER_BIT_NV") ) { return ::hx::Val( COVERAGE_BUFFER_BIT_NV ); }
break;
case 25:
if (HX_FIELD_EQ(inName,"COVERAGE_ALL_FRAGMENTS_NV") ) { return ::hx::Val( COVERAGE_ALL_FRAGMENTS_NV ); }
break;
case 26:
if (HX_FIELD_EQ(inName,"COVERAGE_EDGE_FRAGMENTS_NV") ) { return ::hx::Val( COVERAGE_EDGE_FRAGMENTS_NV ); }
}
return super::__Field(inName,inCallProp);
}
::hx::Val NV_coverage_sample_obj::__SetField(const ::String &inName,const ::hx::Val &inValue,::hx::PropertyAccess inCallProp)
{
switch(inName.length) {
case 19:
if (HX_FIELD_EQ(inName,"COVERAGE_BUFFERS_NV") ) { COVERAGE_BUFFERS_NV=inValue.Cast< int >(); return inValue; }
if (HX_FIELD_EQ(inName,"COVERAGE_SAMPLES_NV") ) { COVERAGE_SAMPLES_NV=inValue.Cast< int >(); return inValue; }
break;
case 21:
if (HX_FIELD_EQ(inName,"COVERAGE_COMPONENT_NV") ) { COVERAGE_COMPONENT_NV=inValue.Cast< int >(); return inValue; }
if (HX_FIELD_EQ(inName,"COVERAGE_AUTOMATIC_NV") ) { COVERAGE_AUTOMATIC_NV=inValue.Cast< int >(); return inValue; }
break;
case 22:
if (HX_FIELD_EQ(inName,"COVERAGE_COMPONENT4_NV") ) { COVERAGE_COMPONENT4_NV=inValue.Cast< int >(); return inValue; }
if (HX_FIELD_EQ(inName,"COVERAGE_ATTACHMENT_NV") ) { COVERAGE_ATTACHMENT_NV=inValue.Cast< int >(); return inValue; }
if (HX_FIELD_EQ(inName,"COVERAGE_BUFFER_BIT_NV") ) { COVERAGE_BUFFER_BIT_NV=inValue.Cast< int >(); return inValue; }
break;
case 25:
if (HX_FIELD_EQ(inName,"COVERAGE_ALL_FRAGMENTS_NV") ) { COVERAGE_ALL_FRAGMENTS_NV=inValue.Cast< int >(); return inValue; }
break;
case 26:
if (HX_FIELD_EQ(inName,"COVERAGE_EDGE_FRAGMENTS_NV") ) { COVERAGE_EDGE_FRAGMENTS_NV=inValue.Cast< int >(); return inValue; }
}
return super::__SetField(inName,inValue,inCallProp);
}
void NV_coverage_sample_obj::__GetFields(Array< ::String> &outFields)
{
outFields->push(HX_("COVERAGE_COMPONENT_NV",e1,59,e0,37));
outFields->push(HX_("COVERAGE_COMPONENT4_NV",f9,fd,0e,90));
outFields->push(HX_("COVERAGE_ATTACHMENT_NV",8d,46,b8,a8));
outFields->push(HX_("COVERAGE_BUFFERS_NV",2b,1d,ec,5b));
outFields->push(HX_("COVERAGE_SAMPLES_NV",55,9d,83,26));
outFields->push(HX_("COVERAGE_ALL_FRAGMENTS_NV",79,00,b4,19));
outFields->push(HX_("COVERAGE_EDGE_FRAGMENTS_NV",ef,e8,79,d6));
outFields->push(HX_("COVERAGE_AUTOMATIC_NV",b3,d6,d0,ac));
outFields->push(HX_("COVERAGE_BUFFER_BIT_NV",a2,50,cd,9f));
super::__GetFields(outFields);
};
#ifdef HXCPP_SCRIPTABLE
static ::hx::StorageInfo NV_coverage_sample_obj_sMemberStorageInfo[] = {
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_COMPONENT_NV),HX_("COVERAGE_COMPONENT_NV",e1,59,e0,37)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_COMPONENT4_NV),HX_("COVERAGE_COMPONENT4_NV",f9,fd,0e,90)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_ATTACHMENT_NV),HX_("COVERAGE_ATTACHMENT_NV",8d,46,b8,a8)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_BUFFERS_NV),HX_("COVERAGE_BUFFERS_NV",2b,1d,ec,5b)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_SAMPLES_NV),HX_("COVERAGE_SAMPLES_NV",55,9d,83,26)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_ALL_FRAGMENTS_NV),HX_("COVERAGE_ALL_FRAGMENTS_NV",79,00,b4,19)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_EDGE_FRAGMENTS_NV),HX_("COVERAGE_EDGE_FRAGMENTS_NV",ef,e8,79,d6)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_AUTOMATIC_NV),HX_("COVERAGE_AUTOMATIC_NV",b3,d6,d0,ac)},
{::hx::fsInt,(int)offsetof(NV_coverage_sample_obj,COVERAGE_BUFFER_BIT_NV),HX_("COVERAGE_BUFFER_BIT_NV",a2,50,cd,9f)},
{ ::hx::fsUnknown, 0, null()}
};
static ::hx::StaticInfo *NV_coverage_sample_obj_sStaticStorageInfo = 0;
#endif
static ::String NV_coverage_sample_obj_sMemberFields[] = {
HX_("COVERAGE_COMPONENT_NV",e1,59,e0,37),
HX_("COVERAGE_COMPONENT4_NV",f9,fd,0e,90),
HX_("COVERAGE_ATTACHMENT_NV",8d,46,b8,a8),
HX_("COVERAGE_BUFFERS_NV",2b,1d,ec,5b),
HX_("COVERAGE_SAMPLES_NV",55,9d,83,26),
HX_("COVERAGE_ALL_FRAGMENTS_NV",79,00,b4,19),
HX_("COVERAGE_EDGE_FRAGMENTS_NV",ef,e8,79,d6),
HX_("COVERAGE_AUTOMATIC_NV",b3,d6,d0,ac),
HX_("COVERAGE_BUFFER_BIT_NV",a2,50,cd,9f),
::String(null()) };
::hx::Class NV_coverage_sample_obj::__mClass;
void NV_coverage_sample_obj::__register()
{
NV_coverage_sample_obj _hx_dummy;
NV_coverage_sample_obj::_hx_vtable = *(void **)&_hx_dummy;
::hx::Static(__mClass) = new ::hx::Class_obj();
__mClass->mName = HX_("lime.graphics.opengl.ext.NV_coverage_sample",cc,ea,05,ca);
__mClass->mSuper = &super::__SGetClass();
__mClass->mConstructEmpty = &__CreateEmpty;
__mClass->mConstructArgs = &__Create;
__mClass->mGetStaticField = &::hx::Class_obj::GetNoStaticField;
__mClass->mSetStaticField = &::hx::Class_obj::SetNoStaticField;
__mClass->mStatics = ::hx::Class_obj::dupFunctions(0 /* sStaticFields */);
__mClass->mMembers = ::hx::Class_obj::dupFunctions(NV_coverage_sample_obj_sMemberFields);
__mClass->mCanCast = ::hx::TCanCast< NV_coverage_sample_obj >;
#ifdef HXCPP_SCRIPTABLE
__mClass->mMemberStorageInfo = NV_coverage_sample_obj_sMemberStorageInfo;
#endif
#ifdef HXCPP_SCRIPTABLE
__mClass->mStaticStorageInfo = NV_coverage_sample_obj_sStaticStorageInfo;
#endif
::hx::_hx_RegisterClass(__mClass->mName, __mClass);
}
} // end namespace lime
} // end namespace graphics
} // end namespace opengl
} // end namespace ext
| [
"ua667766706@gmail.com"
] | ua667766706@gmail.com |
7b07f6b296bcbcd8182344168e86fb15fdee976d | f4d39af1cdd84e1cab81c27bd8c43f79ce45bced | /ch13/ex13-28/main.cc | eff33f492ccd831fff9c7d890088ffb25e2e4746 | [] | no_license | daustria/cpp-primer | d81fcbc60835e3ec1ae9c2cca72b3bb67303ae2f | aee928370b4faad3055c6d09d311c3dca85028a5 | refs/heads/master | 2020-09-05T06:01:05.319204 | 2020-01-02T23:55:09 | 2020-01-02T23:55:09 | 220,005,325 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,149 | cc | #include <string>
#include <iostream>
class TreeNode
{
friend std::ostream &operator<<(std::ostream &out, const TreeNode &);
public:
TreeNode(const std::string s = std::string()):
value(s), count(1), left(nullptr), right(nullptr)
{
}
void setLeft(TreeNode *node)
{
left = node;
updateCount();
}
void setRight(TreeNode *node)
{
right = node;
updateCount();
}
private:
std::string value; //some value
int count; //stores the number of nodes in the tree
TreeNode *left;
TreeNode *right;
void updateCount()
{
int numLeft = 0;
int numRight = 0;
if (left)
numLeft = left->count;
if (right)
numRight = right->count;
count = 1 + numLeft + numRight;
}
};
class BinStrTree
{
private:
TreeNode *root;
};
std::ostream &operator<<(std::ostream &out, const TreeNode &node)
{
out << node.value << " " << node.count;
return out;
}
int main()
{
TreeNode root("root");
TreeNode node1("somenode");
TreeNode node2("someother");
TreeNode node3("0101010101");
node1.setLeft(&node3);
root.setLeft(&node1);
root.setRight(&node2);
std::cout << root << std::endl;
}
| [
"dgaustri@uwaterloo.ca"
] | dgaustri@uwaterloo.ca |
2bef3d4fafd5c8254c8ae301a406b201a339ae42 | c037f3092d3f94a7e6f380184507ab133639cc3d | /src/content/public/browser/data_deleter.h | d8431a481ca59fc9b25f999b2627ffcfcd8d6877 | [
"BSD-3-Clause"
] | permissive | webosose/chromium79 | bab17fe53458195b41251e4d5adfa29116ae89a9 | 57b21279f43f265bf0476d2ebf8fe11c8dee4bba | refs/heads/master | 2022-11-10T03:27:02.861486 | 2020-10-29T11:30:27 | 2020-11-09T05:19:01 | 247,589,218 | 3 | 6 | null | 2022-10-23T11:12:07 | 2020-03-16T02:06:18 | null | UTF-8 | C++ | false | false | 1,845 | h | // Copyright (c) 2020 LG Electronics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef CONTENT_PUBLIC_BROWSER_DATA_DELETER_H_
#define CONTENT_PUBLIC_BROWSER_DATA_DELETER_H_
#include <set>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "url/origin.h"
namespace content {
class DataDeleter {
public:
DataDeleter() = default;
typedef std::set<GURL> Origins;
using CompletionCallback = base::OnceCallback<void()>;
virtual void StartDeleting(const Origins& origins,
CompletionCallback callback) = 0;
virtual void StartDeleting(const GURL& origin,
CompletionCallback callback) = 0;
struct DeletionContext : public base::RefCounted<DeletionContext> {
DeletionContext(const Origins& origins, CompletionCallback& callback);
CompletionCallback callback_;
std::set<GURL> origins_;
};
virtual void OnDeleteCompleted(const GURL& origin,
scoped_refptr<DeletionContext> context) = 0;
DISALLOW_COPY_AND_ASSIGN(DataDeleter);
};
CONTENT_EXPORT void SetDataDeleter(DataDeleter*);
CONTENT_EXPORT DataDeleter* GetDataDeleter();
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_DATA_DELETER_H_
| [
"youngsoo.choi@lge.com"
] | youngsoo.choi@lge.com |
d3407c0ade229c0abfc54437b08b6cdf7eb1cb72 | 910cd385d1d57e5b9f19a1299a3aeb3f5dbe35d8 | /competency2/assignment6.cpp | 3efe35502191e1261c45938c2136b022ffdbf326 | [] | no_license | knowyrrole101/cosc-1337 | f99ec390853a32446079bc1a87938ddab4221ecd | 945a4c8957d58bcc523e9ee5a111eb8657bf6d5f | refs/heads/master | 2021-07-13T14:21:33.376906 | 2019-12-15T04:21:20 | 2019-12-15T04:21:20 | 204,230,552 | 0 | 0 | null | 2020-09-04T22:51:19 | 2019-08-25T01:12:43 | C++ | UTF-8 | C++ | false | false | 6,265 | cpp | //******************************************************************
// Monkey Food - Assignment 6
// Programmer: Mamun Ahmed
// Completed : 10/19/2019
// Status : Completed
//
// Program that accepts user inputs around lbs of food eaten
// by monkeys. The user input accepts floats and validates
// to ensure no negative numbers are passed in. The program
// also calculaties the min, max, and average food for all
// monkeys. Finally a tabular report of all data is printed out
// at the end.
//******************************************************************
#include <iostream> // Handle input/output
#include <iomanip> // I/O manupulator declarations
#include <string> // Strings
using namespace std;
// Constants for Monkey Data Multidimensional array.
const int ROWS = 3;
const int COLS = 7;
// Function Prototypes
void getMonkeysData(double [][COLS], int ROWS); // Get User Input Function
double averageFoodPerDay(double monkeyDataStorage[][COLS], int ROWS); // Average Food Per Day Function
double leastFoodEaten(double monkeyDataStorage[][COLS], int ROWS); // Minimum Value in Multidimensional Array Function
double mostFoodEaten(double monkeyDataStorage[][COLS], int ROWS); // Greatest Value in Multidimensional Array Function
void displayData(double monkeyDataStorage[][COLS], int ROWS, double foodAverage, double minFood, double maxFood); // Display Data
int main()
{
// Variable Declarations
double foodAverage;
double minFood;
double maxFood;
// Two-dimensional Array to Store Monkey Data
double monkeyDataStorage[ROWS][COLS];
// Function Executions
getMonkeysData(monkeyDataStorage, ROWS); // Grab Monkey Data and Pass to Array
foodAverage = averageFoodPerDay(monkeyDataStorage, ROWS); // Grab Average Data
minFood = leastFoodEaten(monkeyDataStorage, ROWS); // Grab Min Data and store
maxFood = mostFoodEaten(monkeyDataStorage, ROWS); // Grab Max Data and store
displayData(monkeyDataStorage, ROWS, foodAverage, minFood, maxFood); // Display the report.
}
// Function That Grabs User Input, Validates, and Stores in Existing Monkey Data Multi-Dimensional Array
void getMonkeysData(double monkeyDataStorage[][COLS], int ROWS)
{
double userInput; // User Input Local Variable
string daysOfWeek[7] = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"}; // Days Array
// Input Loop for Each Monkey and each day.
for(int row=0; row<ROWS; row++)
{
cout << "Enter Data for Monkey "<< row+1 << endl;
for(int col=0; col<COLS; col++)
{
// User Input validation to ensure non-negative numbers
do{
// Grab User Input for Monkey Food
cout << "Enter pounds of food eaten by monkey " << row+1 << " on " << daysOfWeek[col] <<": ";
cin >> userInput; // Store Input in Temp Variable
if(userInput < 0)
{
cout << "Enter a valid number greater than 0! Please Try Again!" << endl;
} else {
monkeyDataStorage[row][col] = userInput; // Pass Temp Data into Appropriate Index
}
} while(userInput<0);
}
}
}
double averageFoodPerDay(double monkeyDataStorage[][COLS], int ROWS){
double sum; // Local variable to sum all values in array
double count = ROWS * COLS; // Total Cell Count;
double average; // Local variable to store calculated average;
for(int row=0; row<ROWS; row++)
{
for(int col=0; col<COLS; col++)
{
sum += monkeyDataStorage[row][col];
}
}
average = sum/count; // Calculate the average
return average; // Return Double Floating Point Average Calculation
}
// Function to Return Minimum Food Eaten
double leastFoodEaten(double monkeyDataStorage[][COLS], int ROWS){
double least; // Local variable to sum all values in array
least = monkeyDataStorage[0][0]; // Assign temp value
for(int row=0; row<ROWS; row++)
{
for(int col=0; col<COLS; col++)
{
if(least > monkeyDataStorage[row][col])
{
least = monkeyDataStorage[row][col];
}
}
}
return least; // Return Minimum Value
}
// Function to Return Maximum Food Eaten
double mostFoodEaten(double monkeyDataStorage[][COLS], int ROWS){
double max; // Local variable to sum all values in array
max = monkeyDataStorage[0][0]; // Assign temp value
for(int row=0; row<ROWS; row++)
{
for(int col=0; col<COLS; col++)
{
if(max < monkeyDataStorage[row][col])
{
max = monkeyDataStorage[row][col];
}
}
}
return max; // Return Maximum Value
}
void displayData(double monkeyDataStorage[][COLS], int ROWS, double foodAverage, double minFood, double maxFood)
{
// Header Text
cout << "Pounds of Food Eaten By Monkey and Day of Week\n" << endl;
cout << fixed << showpoint << setprecision(1); // Set 2 Point Floating Numbers
// Data Column Header
cout << left << setw(10) << "Monkey" << setw(10) << "Sun" << setw(10) << "Mon" << setw(10) << "Tue" << setw(10) << "Wed"
<< setw(10) << "Thu" << setw(10) << "Fri" << setw(10) << "Sat" << endl;
// Iteratively print out all monkey data for each row
for(int count=0; count<ROWS; count++)
{
cout << left << setw(10) << count << setw(10) << monkeyDataStorage[count][0] << setw(10) << monkeyDataStorage[count][1]
<< setw(10) << monkeyDataStorage[count][2] << setw(10) << monkeyDataStorage[count][3] << setw(10) << monkeyDataStorage[count][4]
<< setw(10) << monkeyDataStorage[count][5] << setw(10) << monkeyDataStorage[count][6] << endl;
}
// Print out aggregation metrics
cout << "\n";
cout << left << "The average food eaten per day by all monkeys : " << right << setw(10) << foodAverage << " pounds" << endl;
cout << left << "The least amount of food eaten by any monkey : " << right << setw(10) << minFood << " pounds" << endl;
cout << left << "The largest amount of food eaten by any monkey: " << right << setw(10) << maxFood << " pounds" << endl;
} | [
"moona@indeed.com"
] | moona@indeed.com |
9a1e0d89d6fa9b4d596b92bd74c13c9b75beb58b | 1e6478e0d0054247a7699427eb58d2ca181664de | /Linked List/isPlaindrome.cpp | 6febcdb1829c3611dd3dae478f5d4ca2b6a6caf4 | [] | no_license | Jackent2B/My-DSA | 35c8c1fbb72f655c71f38841f1ac72f9c6110470 | 20ce314cb2a248a86268d03a54d4db997796a7ff | refs/heads/main | 2023-07-12T00:36:05.058944 | 2021-08-11T10:36:56 | 2021-08-11T10:36:56 | 346,273,611 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,045 | cpp | //reverse a linked list
Node* reverse(Node* ptr){
Node* prev,*current,*next;
prev = NULL;
current = ptr;
while(current != NULL){
next = current->next;
current->next = prev;
prev = current;
current = next;
}
ptr = prev;
return ptr;
}
bool isPalindrome(Node *head)
{
//Your code here
Node* slow = head;
Node* fast = head;
//find middle element using tortoise method
while(fast->next != NULL && fast->next->next != NULL){
slow = slow->next;
fast = fast->next->next;
}
Node* reverse_start = slow->next;
//reversing the linked list after middle element
Node* reverse_ptr_head = reverse(reverse_start);
//traversing the linked list from start and from after the middle element
Node* start1 = head;
Node* start2 = reverse_ptr_head;
while(start2 != NULL){
if(start1->data != start2->data){
return 0;
}
start1 = start1->next;
start2 = start2->next;
}
return 1;
} | [
"jayant.khandelwal7@gmail.com"
] | jayant.khandelwal7@gmail.com |
5cc08793f97bcb72ccfa4c1a94a009d9f8cc17f5 | a06368ebe626e2373b3905ed7961fa2517c57ab2 | /Week 3 Program 27.cpp | c3aecc3ae1652f8996be1e6ba91014ab24847658 | [] | no_license | gutty333/Practice-1 | 85fe2d171ea29fa329e953d5449bf9e7eb559bfa | ca88ceefe34e64a35f6ed6ad3a021a7b5a6117b7 | refs/heads/master | 2021-01-10T10:58:07.655402 | 2016-10-25T04:46:38 | 2016-10-25T04:46:38 | 46,999,755 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 156 | cpp | #include <iostream>
using namespace std;
int main()
{
int x = 50;
while (x > 0)
{
cout << x << " seconds to go" << endl;
x--;
}
return 0;
}
| [
"carlos.leonard@binarysword.com"
] | carlos.leonard@binarysword.com |
7a7c6a8c5f8a47bee59e910944ad7ca27869ef37 | bcfcad1c5d202cdaa172014afd260e02ad802cb4 | /LoadedWorld/Include/LoadedWorld.hpp | 0bded95069d692ffcea94207d2eebb6e97fef85b | [
"BSL-1.0",
"LicenseRef-scancode-khronos",
"Zlib",
"MIT"
] | permissive | jordanlittlefair/Foundation | 0ee67940f405573a41be6c46cd9d2e84e34ae8b1 | ab737b933ea5bbe2be76133ed78c8e882f072fd0 | refs/heads/master | 2016-09-06T15:43:27.380878 | 2015-01-20T19:34:32 | 2015-01-20T19:34:32 | 26,716,271 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 794 | hpp | #pragma once
#ifndef _LOADEDWORLD_LOADEDWORLD_HPP_
#define _LOADEDWORLD_LOADEDWORLD_HPP_
#include "../../GameComponentInterfaces/Include/IWorld.hpp"
namespace Fnd
{
namespace LoadedWorld
{
class LoadedWorld:
public Fnd::GameComponentInterfaces::IWorld
{
public:
LoadedWorld();
void SetWorldMessageListener( Fnd::GameComponentInterfaces::IWorldMessageListener* game );
// LoadedWorld only supports a single world file (a single level).
void SetWorldSetupData( const Fnd::Settings::ApplicationSettings::WorldSettings& world_setup_data );
bool Initialise();
~LoadedWorld();
private:
Fnd::GameComponentInterfaces::IWorldMessageListener* _game;
Fnd::Settings::ApplicationSettings::WorldSettings _world_setup_data;
};
}
}
#endif | [
"jordanlittlefair@fsmail.net"
] | jordanlittlefair@fsmail.net |
4a69bee69db0c1c827267a556e96268c1f9b00aa | 8d63452d9dbc650884966b07a5652975f1e71961 | /game_shared/sheetsimulator.cpp | 79993f3b6441ff2fd9c3f119e44b15e88fca7f36 | [] | no_license | 0TheSpy/hl2sdk | d2656cb99304ca8b7be7b67631e45f416539f02c | 8b2833d5909f27219d90000260887a3aeb32d485 | refs/heads/master | 2023-03-15T20:28:37.485807 | 2012-05-30T01:09:21 | 2012-05-30T01:09:21 | null | 0 | 0 | null | null | null | null | WINDOWS-1252 | C++ | false | false | 20,230 | cpp | //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: The Escort's Shield weapon effect
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "sheetsimulator.h"
#include "edict.h"
#include "collisionutils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define COLLISION_PLANE_OFFSET 6.0f
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CSheetSimulator::CSheetSimulator( TraceLineFunc_t traceline,
TraceHullFunc_t traceHull ) :
m_pFixedPoint(0), m_ControlPoints(0),
m_TraceLine(traceline), m_TraceHull(traceHull)
{
}
CSheetSimulator::~CSheetSimulator()
{
if (m_pFixedPoint)
{
delete[] m_pFixedPoint;
delete[] m_ControlPoints;
delete[] m_pCollisionPlanes;
delete[] m_pValidCollisionPlane;
}
delete[] m_Particle;
}
//-----------------------------------------------------------------------------
// Initialization
//-----------------------------------------------------------------------------
void CSheetSimulator::Init( int w, int h, int fixedPointCount )
{
m_ControlPointOffset.Init( 0, 0, 0 );
m_HorizontalCount = w;
m_VerticalCount = h;
m_Particle = new Particle_t[w * h];
m_FixedPointCount = fixedPointCount;
if (fixedPointCount)
{
m_pFixedPoint = new Vector[fixedPointCount];
m_ControlPoints = new Vector[fixedPointCount];
m_pCollisionPlanes = new cplane_t[fixedPointCount];
m_pValidCollisionPlane = new bool[fixedPointCount];
}
// Initialize distances and such
m_Origin = Vector(0, 0, 0);
for ( int i = 0; i < NumParticles(); ++i )
{
m_Particle[i].m_Mass = 1.0f;
m_Particle[i].m_Collided = false;
m_Particle[i].m_Position = Vector(0,0,0);
m_Particle[i].m_Velocity = Vector(0,0,0);
}
}
//-----------------------------------------------------------------------------
// adds springs
//-----------------------------------------------------------------------------
void CSheetSimulator::AddSpring( int p1, int p2, float restLength )
{
int spring = m_Springs.AddToTail();
m_Springs[spring].m_Particle1 = p1;
m_Springs[spring].m_Particle2 = p2;
m_Springs[spring].m_RestLength = restLength;
}
void CSheetSimulator::AddFixedPointSpring( int fixedPoint, int p, float restLength )
{
assert( fixedPoint < m_FixedPointCount );
int spring = m_Springs.AddToTail();
m_Springs[spring].m_Particle1 = p;
m_Springs[spring].m_Particle2 = -(fixedPoint+1);
m_Springs[spring].m_RestLength = restLength;
}
//-----------------------------------------------------------------------------
// Gravity
//-----------------------------------------------------------------------------
void CSheetSimulator::SetGravityConstant( float g )
{
m_GravityConstant = g;
}
void CSheetSimulator::AddGravityForce( int particle )
{
m_Gravity.AddToTail( particle );
}
//-----------------------------------------------------------------------------
// spring constants....
//-----------------------------------------------------------------------------
void CSheetSimulator::SetPointSpringConstant( float constant )
{
m_PointSpringConstant = constant;
}
void CSheetSimulator::SetFixedSpringConstant( float constant )
{
m_FixedSpringConstant = constant;
}
void CSheetSimulator::SetViscousDrag( float drag )
{
m_ViscousDrag = drag;
}
void CSheetSimulator::SetSpringDampConstant( float damp )
{
m_DampConstant = damp;
}
//-----------------------------------------------------------------------------
// Sets the collision group
//-----------------------------------------------------------------------------
void CSheetSimulator::SetCollisionGroup( int group )
{
m_CollisionGroup = group;
}
//-----------------------------------------------------------------------------
// bounding box for collision
//-----------------------------------------------------------------------------
void CSheetSimulator::SetBoundingBox( Vector& mins, Vector& maxs )
{
m_FrustumBoxMin = mins;
m_FrustumBoxMax = maxs;
}
//-----------------------------------------------------------------------------
// bounding box for collision
//-----------------------------------------------------------------------------
void CSheetSimulator::ComputeBounds( Vector& mins, Vector& maxs )
{
VectorCopy( m_Particle[0].m_Position, mins );
VectorCopy( m_Particle[0].m_Position, maxs );
for (int i = 1; i < NumParticles(); ++i)
{
VectorMin( mins, m_Particle[i].m_Position, mins );
VectorMax( maxs, m_Particle[i].m_Position, maxs );
}
mins -= m_Origin;
maxs -= m_Origin;
}
//-----------------------------------------------------------------------------
// Set the shield position
//-----------------------------------------------------------------------------
void CSheetSimulator::SetPosition( const Vector& origin, const QAngle& angles )
{
// FIXME: Need a better metric for position reset
if (m_Origin.DistToSqr(origin) > 1e3)
{
for ( int i = 0; i < NumParticles(); ++i )
{
m_Particle[i].m_Position = origin;
m_Particle[i].m_Velocity = Vector(0,0,0);
}
}
m_Origin = origin;
m_Angles = angles;
ComputeControlPoints();
}
//-----------------------------------------------------------------------------
// get at the points
//-----------------------------------------------------------------------------
int CSheetSimulator::NumHorizontal() const
{
return m_HorizontalCount;
}
int CSheetSimulator::NumVertical() const
{
return m_VerticalCount;
}
int CSheetSimulator::PointCount() const
{
return m_HorizontalCount * m_VerticalCount;
}
const Vector& CSheetSimulator::GetPoint( int x, int y ) const
{
return m_Particle[y * NumHorizontal() + x].m_Position;
}
const Vector& CSheetSimulator::GetPoint( int i ) const
{
return m_Particle[i].m_Position;
}
// Fixed points
Vector& CSheetSimulator::GetFixedPoint( int i )
{
assert( i < m_FixedPointCount );
return m_pFixedPoint[i];
}
//-----------------------------------------------------------------------------
// For offseting the control points
//-----------------------------------------------------------------------------
void CSheetSimulator::SetControlPointOffset( const Vector& offset )
{
VectorCopy( offset, m_ControlPointOffset );
}
//-----------------------------------------------------------------------------
// Compute the position of the fixed points
//-----------------------------------------------------------------------------
void CSheetSimulator::ComputeControlPoints()
{
//trace_t tr;
Vector forward, right, up;
AngleVectors(m_Angles, &forward, &right, &up);
for (int i = 0; i < m_FixedPointCount; ++i)
{
VectorAdd( m_Origin, m_ControlPointOffset, m_ControlPoints[i] );
m_ControlPoints[i] += right * m_pFixedPoint[i].x;
m_ControlPoints[i] += up * m_pFixedPoint[i].z;
m_ControlPoints[i] += forward * m_pFixedPoint[i].y;
}
}
//-----------------------------------------------------------------------------
// Clear forces + velocities affecting each point
//-----------------------------------------------------------------------------
void CSheetSimulator::ClearForces()
{
int i;
for ( i = 0; i < NumParticles(); ++i)
{
m_Particle[i].m_Force = Vector(0,0,0);
}
}
//-----------------------------------------------------------------------------
// Update the shield positions
//-----------------------------------------------------------------------------
void CSheetSimulator::ComputeForces()
{
float springConstant;
int i;
for ( i = 0; i < m_Springs.Size(); ++i )
{
// Hook's law for a damped spring:
// got two particles, a and b with positions xa and xb and velocities va and vb
// and l = xa - xb
// fa = -( ks * (|l| - r) + kd * (va - vb) dot (l) / |l|) * l/|l|
Vector dx, dv, force;
if (m_Springs[i].m_Particle2 < 0)
{
// Case where we're connected to a control point
dx = m_Particle[m_Springs[i].m_Particle1].m_Position -
m_ControlPoints[- m_Springs[i].m_Particle2 - 1];
dv = m_Particle[m_Springs[i].m_Particle1].m_Velocity;
springConstant = m_FixedSpringConstant;
}
else
{
// Case where we're connected to another part of the shield
dx = m_Particle[m_Springs[i].m_Particle1].m_Position -
m_Particle[m_Springs[i].m_Particle2].m_Position;
dv = m_Particle[m_Springs[i].m_Particle1].m_Velocity -
m_Particle[m_Springs[i].m_Particle2].m_Velocity;
springConstant = m_PointSpringConstant;
}
float length = dx.Length();
if (length < 1e-6)
continue;
dx /= length;
float springfactor = springConstant * ( length - m_Springs[i].m_RestLength);
float dampfactor = m_DampConstant * DotProduct( dv, dx );
force = dx * -( springfactor + dampfactor );
m_Particle[m_Springs[i].m_Particle1].m_Force += force;
if (m_Springs[i].m_Particle2 >= 0)
m_Particle[m_Springs[i].m_Particle2].m_Force -= force;
assert( _finite( m_Particle[m_Springs[i].m_Particle1].m_Force.x ) &&
_finite( m_Particle[m_Springs[i].m_Particle1].m_Force.y) &&
_finite( m_Particle[m_Springs[i].m_Particle1].m_Force.z) );
}
// gravity term
for (i = 0; i < m_Gravity.Count(); ++i)
{
m_Particle[m_Gravity[i]].m_Force.z -= m_Particle[m_Gravity[i]].m_Mass * m_GravityConstant;
}
// viscous drag term
for (i = 0; i < NumParticles(); ++i)
{
// Factor out bad forces for surface contact
// Do this before the drag term otherwise the drag will be too large
if ((m_Particle[i].m_CollisionPlane) >= 0)
{
const Vector& planeNormal = m_pCollisionPlanes[m_Particle[i].m_CollisionPlane].normal;
float perp = DotProduct( m_Particle[i].m_Force, planeNormal );
if (perp < 0)
m_Particle[i].m_Force -= planeNormal * perp;
}
Vector drag = m_Particle[i].m_Velocity * m_ViscousDrag;
m_Particle[i].m_Force -= drag;
}
}
//-----------------------------------------------------------------------------
// Used for testing neighbors against a particular plane
//-----------------------------------------------------------------------------
void CSheetSimulator::TestVertAgainstPlane( int vert, int plane, bool bFarTest )
{
if (!m_pValidCollisionPlane[plane])
return;
// Compute distance to the plane under consideration
cplane_t* pPlane = &m_pCollisionPlanes[plane];
Ray_t ray;
ray.Init( m_Origin, m_Particle[vert].m_Position );
float t = IntersectRayWithPlane( ray, *pPlane );
if (!bFarTest || (t <= 1.0f))
{
if ((t < m_Particle[vert].m_CollisionDist) && (t >= 0.0f))
{
m_Particle[vert].m_CollisionDist = t;
m_Particle[vert].m_CollisionPlane = plane;
}
}
}
//-----------------------------------------------------------------------------
// Collision detect
//-----------------------------------------------------------------------------
void CSheetSimulator::InitPosition( int i )
{
// Collision test...
// Check a line that goes farther out than our current point...
// This will let us check for resting contact
trace_t tr;
m_TraceHull(m_Origin, m_ControlPoints[i], m_FrustumBoxMin, m_FrustumBoxMax,
MASK_SOLID_BRUSHONLY, m_CollisionGroup, &tr );
if ( tr.fraction - 1.0 < 0 )
{
memcpy( &m_pCollisionPlanes[i], &tr.plane, sizeof(cplane_t) );
m_pCollisionPlanes[i].dist += COLLISION_PLANE_OFFSET;
// The trace endpos represents where the center of the box
// ends up being. We actually want to choose a point which is on the
// collision plane
Vector delta;
VectorSubtract( m_ControlPoints[i], m_Origin, delta );
int maxdist = static_cast<int>(VectorNormalize( delta ));
float dist = (m_pCollisionPlanes[i].dist - DotProduct( m_Origin, m_pCollisionPlanes[i].normal )) /
DotProduct( delta, m_pCollisionPlanes[i].normal );
if (dist > maxdist)
dist = maxdist;
VectorMA( m_Origin, dist, delta, m_Particle[i].m_Position );
m_pValidCollisionPlane[i] = true;
}
else if (tr.allsolid || tr.startsolid)
{
m_pValidCollisionPlane[i] = true;
VectorSubtract( m_Origin, m_ControlPoints[i], m_pCollisionPlanes[i].normal );
VectorNormalize( m_pCollisionPlanes[i].normal );
m_pCollisionPlanes[i].dist = DotProduct( m_Origin, m_pCollisionPlanes[i].normal ) - COLLISION_PLANE_OFFSET;
m_pCollisionPlanes[i].type = 3;
}
else
{
VectorCopy( m_ControlPoints[i], m_Particle[i].m_Position );
m_pValidCollisionPlane[i] = false;
}
}
//-----------------------------------------------------------------------------
// Collision detect
//-----------------------------------------------------------------------------
void CSheetSimulator::DetectCollision( int i, float flPlaneOffset )
{
// Collision test...
// Check a line that goes farther out than our current point...
// This will let us check for resting contact
// Vector endpt = m_Particle[i].m_Position;
trace_t tr;
m_TraceHull(m_Origin, m_ControlPoints[i], m_FrustumBoxMin, m_FrustumBoxMax,
MASK_SOLID_BRUSHONLY, m_CollisionGroup, &tr );
if ( tr.fraction - 1.0 < 0 )
{
m_pValidCollisionPlane[i] = true;
memcpy( &m_pCollisionPlanes[i], &tr.plane, sizeof(cplane_t) );
m_pCollisionPlanes[i].dist += flPlaneOffset;
}
else if (tr.allsolid || tr.startsolid)
{
m_pValidCollisionPlane[i] = true;
VectorSubtract( m_Origin, m_ControlPoints[i], m_pCollisionPlanes[i].normal );
VectorNormalize( m_pCollisionPlanes[i].normal );
m_pCollisionPlanes[i].dist = DotProduct( m_Origin, m_pCollisionPlanes[i].normal ) - flPlaneOffset;
m_pCollisionPlanes[i].type = 3;
}
else
{
m_pValidCollisionPlane[i] = false;
}
}
//-----------------------------------------------------------------------------
// Collision plane fixup
//-----------------------------------------------------------------------------
void CSheetSimulator::DetermineBestCollisionPlane( bool bFarTest )
{
// Check neighbors for violation of collision plane constraints
for ( int i = 0; i < NumVertical(); ++i)
{
for ( int j = 0; j < NumHorizontal(); ++j)
{
// Here's the particle we're making springs for
int idx = i * NumHorizontal() + j;
// Now that we've seen all collisions, find the best collision plane
// to use (look at myself and all neighbors). The best plane
// is the one that comes closest to the origin.
m_Particle[idx].m_CollisionDist = FLT_MAX;
m_Particle[idx].m_CollisionPlane = -1;
TestVertAgainstPlane( idx, idx, bFarTest );
if (j > 0)
{
TestVertAgainstPlane( idx, idx-1, bFarTest );
}
if (j < NumHorizontal() - 1)
{
TestVertAgainstPlane( idx, idx+1, bFarTest );
}
if (i > 0)
TestVertAgainstPlane( idx, idx-NumHorizontal(), bFarTest );
if (i < NumVertical() - 1)
TestVertAgainstPlane( idx, idx+NumHorizontal(), bFarTest );
}
}
}
//-----------------------------------------------------------------------------
// satify collision constraints
//-----------------------------------------------------------------------------
void CSheetSimulator::SatisfyCollisionConstraints()
{
// Eliminate velocity perp to a collision plane
for ( int i = 0; i < NumParticles(); ++i )
{
// The actual collision plane
if (m_Particle[i].m_CollisionPlane >= 0)
{
cplane_t* pPlane = &m_pCollisionPlanes[m_Particle[i].m_CollisionPlane];
// Fix up position so it lies on the plane
Vector delta = m_Particle[i].m_Position - m_Origin;
m_Particle[i].m_Position = m_Origin + delta * m_Particle[i].m_CollisionDist;
float perp = DotProduct( m_Particle[i].m_Velocity, pPlane->normal );
if (perp < 0)
m_Particle[i].m_Velocity -= pPlane->normal * perp;
}
}
}
//-----------------------------------------------------------------------------
// integrator
//-----------------------------------------------------------------------------
void CSheetSimulator::EulerStep( float dt )
{
ClearForces();
ComputeForces();
// Update positions and velocities
for ( int i = 0; i < NumParticles(); ++i)
{
m_Particle[i].m_Position += m_Particle[i].m_Velocity * dt;
m_Particle[i].m_Velocity += m_Particle[i].m_Force * dt / m_Particle[i].m_Mass;
assert( _finite( m_Particle[i].m_Velocity.x ) &&
_finite( m_Particle[i].m_Velocity.y) &&
_finite( m_Particle[i].m_Velocity.z) );
// clamp for stability
float lensq = m_Particle[i].m_Velocity.LengthSqr();
if (lensq > 1e6)
{
m_Particle[i].m_Velocity *= 1e3 / sqrt(lensq);
}
}
SatisfyCollisionConstraints();
}
//-----------------------------------------------------------------------------
// Update the shield position:
//-----------------------------------------------------------------------------
void CSheetSimulator::Simulate( float dt )
{
// Initialize positions if necessary
EulerStep(dt);
}
void CSheetSimulator::Simulate( float dt, int steps )
{
ComputeControlPoints();
// Initialize positions if necessary
dt /= steps;
for (int i = 0; i < steps; ++i)
{
// Each step, we want to re-select the best collision planes to constrain
// the movement by
DetermineBestCollisionPlane();
EulerStep(dt);
}
}
#define CLAMP_DIST 6.0
void CSheetSimulator::ClampPointsToCollisionPlanes()
{
// Find collision planes to clamp to
DetermineBestCollisionPlane( false );
// Eliminate velocity perp to a collision plane
for ( int i = 0; i < NumParticles(); ++i )
{
// The actual collision plane
if (m_Particle[i].m_CollisionPlane >= 0)
{
cplane_t* pPlane = &m_pCollisionPlanes[m_Particle[i].m_CollisionPlane];
// Make sure we have a close enough perpendicular distance to the plane...
float flPerpDist = fabs ( DotProduct( m_Particle[i].m_Position, pPlane->normal ) - pPlane->dist );
if (flPerpDist >= CLAMP_DIST)
continue;
// Drop it along the perp
VectorMA( m_Particle[i].m_Position, -flPerpDist, pPlane->normal, m_Particle[i].m_Position );
}
}
}
//-----------------------------------------------------------------------------
// Class to help dealing with the iterative computation
//-----------------------------------------------------------------------------
CIterativeSheetSimulator::CIterativeSheetSimulator( TraceLineFunc_t traceline, TraceHullFunc_t traceHull ) :
CSheetSimulator( traceline, traceHull ),
m_SimulationSteps(0)
{
}
void CIterativeSheetSimulator::BeginSimulation( float dt, int steps, int substeps, int collisionCount )
{
m_CurrentCollisionPt = 0;
m_TimeStep = dt;
m_SimulationSteps = steps;
m_TotalSteps = steps;
m_SubSteps = substeps;
m_InitialPass = true;
m_CollisionCount = collisionCount;
}
bool CIterativeSheetSimulator::Think( )
{
assert( m_SimulationSteps >= 0 );
// Need to iteratively perform collision detection
if (m_CurrentCollisionPt >= 0)
{
DetectCollisions();
return false;
}
else
{
// Simulate it a bunch of times
Simulate(m_TimeStep, static_cast<int>(m_SubSteps));
// Reset the collision point for collision detect
m_CurrentCollisionPt = 0;
--m_SimulationSteps;
if ( m_SimulationSteps == 0 )
{
ClampPointsToCollisionPlanes();
}
return true;
}
}
// Iterative collision detection
void CIterativeSheetSimulator::DetectCollisions( void )
{
for ( int i = 0; i < m_CollisionCount; ++i )
{
if (m_InitialPass)
{
InitPosition( m_CurrentCollisionPt );
}
else
{
float flOffset = COLLISION_PLANE_OFFSET * ( (float)(m_SimulationSteps - 1) / (float)(m_TotalSteps - 1) );
DetectCollision( m_CurrentCollisionPt, flOffset );
}
if (++m_CurrentCollisionPt >= NumParticles())
{
m_CurrentCollisionPt = -1;
m_InitialPass = false;
break;
}
}
}
| [
"ds@alliedmods.net"
] | ds@alliedmods.net |
525c51babf7ebd33ea7466dfd8d895a06c4c2f88 | e31c1d9cdabbebe2d82d492331f8c9b4ebefc681 | /Turn_Off_All_LEDs.ino | 28c51c23d62725dbb5366654a551e5f744cdfd1e | [] | no_license | teejay6/FastLED | ff6c472b8411bea32c941f9be26f370c9f11bc0e | c496fb1ddf61e13c7a0c9da0fbc0dd8a6f362149 | refs/heads/master | 2020-07-14T05:47:38.268629 | 2019-09-10T15:55:23 | 2019-09-10T15:55:23 | 205,253,473 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 708 | ino |
// Configured for Arduino Due
// Configured for LPD8806 LED strip from Adafruit
// Sketch Modifications by TomJ
// Include FastLED Library
#include <FastLED.h>
// How many LEDs in your strip?
#define NUM_LEDS 32
// LPD8806 LED chipsets are SPI based (four wires - data, clock,
// ground, and power), need to define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 3
#define CLOCK_PIN 13
//Correct LPD8806 for Color Order
#define COLOR_ORDER GRB
// Define the array of LEDs
CRGB leds[NUM_LEDS];
void setup() {
// LPD8806 LEDs arrangement.
FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
void loop() {
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
}
| [
"noreply@github.com"
] | noreply@github.com |
ce03448c80858b03ad624acd39297eec3d5a6c44 | 123935d4f1d273b82affdceb0815b4d67b2bc0d8 | /src/share/core_configuration/core_configuration.hpp | 77c20d25b53781a2161f64f53a458918300f534c | [
"Unlicense"
] | permissive | k2m5t2/Karabiner-Elements | 2591d49c68a01b4efa08e3a1d3479bf387072106 | 09d861860fb8125336f0c8a7f83e7c8790ea9793 | refs/heads/master | 2023-03-28T10:40:52.574541 | 2021-03-23T15:11:39 | 2021-03-23T15:11:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,699 | hpp | #pragma once
#include "connected_devices/connected_devices.hpp"
#include "constants.hpp"
#include "details/global_configuration.hpp"
#include "details/profile.hpp"
#include "details/profile/complex_modifications.hpp"
#include "details/profile/device.hpp"
#include "details/profile/simple_modifications.hpp"
#include "details/profile/virtual_hid_keyboard.hpp"
#include "json_utility.hpp"
#include "json_writer.hpp"
#include "logger.hpp"
#include "types.hpp"
#include <fstream>
#include <glob/glob.hpp>
#include <pqrs/filesystem.hpp>
#include <pqrs/osx/process_info.hpp>
#include <pqrs/osx/session.hpp>
#include <string>
#include <unordered_map>
// Example: tests/src/core_configuration/json/example.json
namespace krbn {
namespace core_configuration {
using namespace std::string_literals;
class core_configuration final {
public:
core_configuration(const core_configuration&) = delete;
core_configuration(const std::string& file_path,
uid_t expected_file_owner) : loaded_(false),
global_configuration_(nlohmann::json::object()) {
bool valid_file_owner = false;
// Load karabiner.json only when the owner is root or current session user.
if (pqrs::filesystem::exists(file_path)) {
if (pqrs::filesystem::is_owned(file_path, 0)) {
valid_file_owner = true;
} else {
if (pqrs::filesystem::is_owned(file_path, expected_file_owner)) {
valid_file_owner = true;
}
}
if (!valid_file_owner) {
logger::get_logger()->warn("{0} is not owned by a valid user.", file_path);
} else {
std::ifstream input(file_path);
if (input) {
try {
json_ = json_utility::parse_jsonc(input);
if (auto v = pqrs::json::find_object(json_, "global")) {
global_configuration_ = details::global_configuration(v->value());
}
if (auto v = pqrs::json::find_array(json_, "profiles")) {
for (const auto& profile_json : v->value()) {
profiles_.emplace_back(profile_json);
}
}
loaded_ = true;
} catch (std::exception& e) {
logger::get_logger()->error("parse error in {0}: {1}", file_path, e.what());
json_ = nlohmann::json::object();
}
} else {
logger::get_logger()->error("failed to open {0}", file_path);
}
}
}
// Fallbacks
if (profiles_.empty()) {
profiles_.emplace_back(nlohmann::json({
{"name", "Default profile"},
{"selected", true},
}));
}
}
nlohmann::json to_json(void) const {
auto j = json_;
j["global"] = global_configuration_.to_json();
j["profiles"] = profiles_;
return j;
}
bool is_loaded(void) const { return loaded_; }
const details::global_configuration& get_global_configuration(void) const {
return global_configuration_;
}
details::global_configuration& get_global_configuration(void) {
return global_configuration_;
}
const std::vector<details::profile>& get_profiles(void) const {
return profiles_;
}
void set_profile_name(size_t index, const std::string name) {
if (index < profiles_.size()) {
profiles_[index].set_name(name);
}
}
void select_profile(size_t index) {
if (index < profiles_.size()) {
for (size_t i = 0; i < profiles_.size(); ++i) {
if (i == index) {
profiles_[i].set_selected(true);
} else {
profiles_[i].set_selected(false);
}
}
}
}
void push_back_profile(void) {
profiles_.emplace_back(nlohmann::json({
{"name", "New profile"},
}));
}
void erase_profile(size_t index) {
if (index < profiles_.size()) {
if (profiles_.size() > 1) {
profiles_.erase(profiles_.begin() + index);
}
}
}
const details::profile& get_selected_profile(void) const {
for (auto&& profile : profiles_) {
if (profile.get_selected()) {
return profile;
}
}
return profiles_[0];
}
details::profile& get_selected_profile(void) {
return const_cast<details::profile&>(static_cast<const core_configuration&>(*this).get_selected_profile());
}
// Note:
// Be careful calling `save` method.
// If the configuration file is corrupted temporarily (user editing the configuration file in editor),
// the user data will be lost by the `save` method.
// Thus, we should call the `save` method only when it is neccessary.
void sync_save_to_file(void) {
pqrs::osx::process_info::scoped_sudden_termination_blocker sudden_termination_blocker;
make_backup_file();
remove_old_backup_files();
auto file_path = constants::get_user_core_configuration_file_path();
json_writer::sync_save_to_file(to_json(), file_path, 0700, 0600);
}
private:
void make_backup_file(void) {
auto file_path = constants::get_user_core_configuration_file_path();
if (!pqrs::filesystem::exists(file_path)) {
return;
}
auto backups_directory = constants::get_user_core_configuration_automatic_backups_directory();
if (backups_directory.empty()) {
return;
}
pqrs::filesystem::create_directory_with_intermediate_directories(backups_directory, 0700);
auto backup_file_path = backups_directory +
"/karabiner_" + make_current_local_yyyymmdd_string() + ".json";
if (pqrs::filesystem::exists(backup_file_path)) {
return;
}
pqrs::filesystem::copy(file_path, backup_file_path);
}
void remove_old_backup_files(void) {
auto backups_directory = constants::get_user_core_configuration_automatic_backups_directory();
if (backups_directory.empty()) {
return;
}
auto pattern = backups_directory + "/karabiner_????????.json";
auto paths = glob::glob(pattern);
std::sort(std::begin(paths), std::end(paths));
const int keep_count = 20;
if (paths.size() > keep_count) {
for (int i = 0; i < paths.size() - keep_count; ++i) {
std::error_code error_code;
std::filesystem::remove(paths[i], error_code);
}
}
}
static std::string make_current_local_yyyymmdd_string(void) {
auto t = time(nullptr);
tm tm;
localtime_r(&t, &tm);
return fmt::format("{0:04d}{1:02d}{2:02d}",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday);
}
nlohmann::json json_;
bool loaded_;
details::global_configuration global_configuration_;
std::vector<details::profile> profiles_;
};
} // namespace core_configuration
} // namespace krbn
| [
"tekezo@pqrs.org"
] | tekezo@pqrs.org |
ff2aeedb8828c8c6152b0b13c9d3cde753e8cdc4 | a947cb3a973552101602cb4b5f823fa8b7224bbe | /manipulator/settings.h | 17ff16d1bcdf722b63c0abde1d7859f39593854c | [] | no_license | Skyendless/MiniBot | d1c70672520a70c4b47ea084e7d75dccd99ef09c | 659111c8daef7b8b28fdeb9e3710193aecec339f | refs/heads/master | 2020-04-07T05:18:40.798361 | 2019-02-21T15:48:44 | 2019-02-21T15:48:44 | 158,091,913 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 306 | h | #ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QSettings>
class Settings : public QObject
{
Q_OBJECT
public:
explicit Settings(QObject *parent = nullptr);
static Settings * instance();
signals:
public slots:
private:
QSettings *m_settings;
};
#endif // SETTINGS_H
| [
"chenhaowen01@qq.com"
] | chenhaowen01@qq.com |
ff18eb847db0bb46e9e1c229730f3168788da169 | e12b5ffa7153c58c16e25cd4475189f56e4eb9d1 | /Explanation/P1271 【深基9.例1】选举学生会.cpp | d0db5b676114adb22caa17ca905dc9b01911814b | [] | no_license | hhhnnn2112-Home/NOI-ACcode-Explanation | ef1cdf60504b3bd01ba96f93519dde5aa1aec7ad | 821b08584b804a2ae425f3f7294cc99bd87c9f5b | refs/heads/main | 2023-02-01T02:20:00.421990 | 2020-12-15T10:11:22 | 2020-12-15T10:11:22 | 321,634,613 | 1 | 0 | null | 2020-12-15T10:36:22 | 2020-12-15T10:36:21 | null | UTF-8 | C++ | false | false | 261 | cpp | #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int m,n; cin >> m >> n;
int* x = new int[n];
for (int i = 0; i < n; i++)
cin >> x[i];
sort(x, x + n);
for (int i = 0; i < n; i++)
cout << x[i]<<" ";
} | [
"48145116+hhhnnn2112@users.noreply.github.com"
] | 48145116+hhhnnn2112@users.noreply.github.com |
18245ae90926b87dd9b6a697e4a9c07c971d3441 | 71dd5f7f6275a294bea931f57410a09f33788f36 | /NetworkSim/dynamiclist_xmlparser_itemsdata.cpp | 7ae445611c00b8764b2694502fe08f8d507bdee7 | [] | no_license | higginsrty/RoutingApp | ba308603187ea810ae6ec5de17ae3ed6730dc79c | 8485a40e99d89e06f99dad317fd65be30efd8c2c | refs/heads/master | 2021-01-24T22:27:16.321985 | 2014-03-19T02:24:31 | 2014-03-19T02:25:03 | 15,958,979 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,199 | cpp | #include"stdafx.h"
#include "dynamiclist_xmlparser_itemsdata.h"
#include "dynamicList_common_globaldata.h"
static const QString KDestinationElement = "Destination";
static const QString KWeightElement = "Weight";
static const QString KGatewayElement = "Gateway";
extern GlobalData*iGlobalData;
dynamiclist_xmlparser_itemsData::dynamiclist_xmlparser_itemsData(QObject *parent) : QObject(parent)
{
}
void dynamiclist_xmlparser_itemsData::ParseScreeningsXmlData(const QString& aScreeningFilePath)
{
QFile* File = new QFile(aScreeningFilePath);
//can't open. Display Error
if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
{
return;
}
QDomDocument doc("mydocument");
if(!doc.setContent(file))
{
return;
}
//get the root element
iGlobalData->iListDataArray.clear();
QDomElement docElem = doc.documentElement();
//check root tag name if it matters??
QString rootTag = docElem.tagName(); //root
//get the node's destinations
QDomNodeList nodeList = docElem.elementsByTagName(KDestinationElement);
//check each node
for(int iNodeCount = 0;iNodeCount < nodeList.count(); iNodeCount++)
{
dynamiclist_dto_listnodedata*idynamiclist_dto_listnodedata = new dynamiclist_dto_listnodedata();
//get the current one as QDomElement
QDomElement e1 = nodeList.at(iNodeCount).toElement();
//get all data for the element by looping through all child elements
QDomNode pEntries = e1.firstChild();
while(!pEntries.isNull()){
QDomElement perData = pEntries.toElement();
QString tagNam = perData.tagName();
if(tagName == KDestinationElement){
idynamiclist_dto_listnodedata->SetItemDestination(perData.text());
}else if(tagNam == KWeightElement){
idynamiclist_dto_listnodedata->SetItemWeight(perData.text());
}else if(tagNam == KGatewayElement){
idynamiclist_dto_listnodedata->SetItemGateway(perData.text());
}
pEntries = pEntries.nextSibling();
}//end of while
iGlobalData->iListDataArray.append(idynamiclist_dto_listnodedata);
ItemsMasterList.append(idynamiclist_dto_listnodedata);
}//end of for loop
file->close();
if(ItemMasterList.count()%10==0)
iGlobalData->iResultPageCount = (ItemsMasterList.count()/10);
else
{
iGlobalData->iResultPageCount = (ItemsMasterList.count()/10);
iGlobalData->iResultPageCount = iGlobalData->iResultPageCount+1;
}
QString qStr = QString::number(iGlobalData->iResultPageCount);
SetiResultPageCount(qStr);
}
//Get first 10 elements from array
QList<QObject*> dynamiclist_xmlparser_itemsData::ExtractItems() //called from listviewRT::createlistview()
{
QList<QObject*>iTempItemsList;
for(int ifilmitemcount = iGlobalData->iInitialNumRecords;ifilmitemcount<iGlobalData->iFinalNumRecords;ifilmitemcount++)
{
iTempItemsList.append(ItemsMasterList.at(ifilmitemcount));
}
QString qStr = QString::number(iGlobalData->upperpagecount);
SetiResultUpper_Lower(qStr);
return iTempItemList;
}//end of extract items
| [
"riley_is_white@hotmail.com"
] | riley_is_white@hotmail.com |
918e043f098909a77e28545e26bbe1a75e5cb01b | a78c0d80239f6a372c16cf82d01c617c83b148e0 | /World Simulator - Mineral Extraction Robots - C++/Source code/Analyser.cpp | 29655bc18b51d93d64f9008716128a98992c1d36 | [] | no_license | johnbaris/johnbaris.github.io | 6a30b2e72416ed82db645a65379ea4e62f8958b8 | 38393f8326f1fe5eba0a1bf8463fbcee9f665b4f | refs/heads/master | 2020-06-21T20:38:07.457937 | 2018-07-08T19:29:57 | 2018-07-08T19:29:57 | 74,771,014 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 11,358 | cpp | #include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
#include "Analyser.h"
int counter = 0;
int analcount = 0;
int Analyser::totalMinedCargo = 0;
Analyser::Analyser(int _x, int _y, int _moveCount, int _damageCount, float _maxCargo, float _mineCargo,
float _palladium, float _iridium, float _platinum, float _totalCargo, bool _minedmg)
: Robot(_x, _y, _moveCount, _damageCount)
{
//setState(false);
setType(1);
setMaxCargo(_maxCargo);
setMineCargo(_mineCargo);
setPalladiumCargo(_palladium);
setIridiumCargo(_iridium);
setPlatinumCargo(_platinum);
setTotalCargo(_totalCargo);
setMineDamage(_minedmg);
analcount++;
string Result; // string which will contain the result
ostringstream convert; // stream used for the conversion
convert << analcount; // insert the textual representation of 'Number' in the characters in the stream
Result = convert.str();
Result = "A" + Result;
setID(Result);
}
float Analyser::getMaxCargo() const
{
return maxCargo;
}
void Analyser::setMaxCargo(float _maxCargo)
{
maxCargo = _maxCargo;
}
float Analyser::getPalladiumCargo() const
{
return palladiumCargo;
}
void Analyser::setPalladiumCargo(float _paladium)
{
palladiumCargo = _paladium;
}
float Analyser::getIridiumCargo() const
{
return iridiumCargo;
}
void Analyser::setIridiumCargo(float _iridium)
{
iridiumCargo = _iridium;
}
float Analyser::getPlatinumCargo() const
{
return platinumCargo;
}
void Analyser::setPlatinumCargo(float _platinum)
{
platinumCargo = _platinum;
}
float Analyser::getMineCargo() const
{
return mineCargo;
}
void Analyser::setMineCargo(float _mineCargo)
{
mineCargo = _mineCargo;
}
float Analyser::getTotalCargo() const
{
return totalCargo;
}
void Analyser::setTotalCargo(float _totalCargo)
{
totalCargo = _totalCargo;
}
bool Analyser::isMineDamaged()
{
return mineDamage;
}
void Analyser::setMineDamage(bool _mineDamage)
{
mineDamage = _mineDamage;
}
int Analyser::getMaxAmount(Ground * ground[])
{
/* Vriskoume poio sustatiko exei tin megaluteri periektikotita stin
sigkekrimeni perioxi prokeimenou na ginei eksoruksi */
int max = ground[getX()][getY()].getPalladium();
int ore = 0;
if (ground[getX()][getY()].getIridium() > max)
{
max = ground[getX()][getY()].getIridium();
ore = 1;
}
if (ground[getX()][getY()].getPlatinum() > max)
{
max = ground[getX()][getY()].getPlatinum();
ore = 2;
}
return ore;
}
int Analyser::getTotalMinedCargo()
{
return totalMinedCargo;
}
void Analyser::checkForMineDamage()
{
int perc;
perc = 1 + rand() % 100;
if (perc <= 10)
{
setMineDamage(true);
setRoundDamaged(getRoundDamaged() + 1);
setDamageCount(getDamageCount() + 1); /* Auksanoume tis sunolikes vlaves p exei pathei */
Robot::updateTotalDamageCount(getDamageCount());
cout << "To robot " << getID() << " xalase logo eksoruksis." << endl;
}
else
{
setMineDamage(false);
}
}
void Analyser::leitourgia(Map * map, Ground * ground[], Base * base, vector< Robot * > robots)
{
int ore;
float amount; /* periektikotita sustatikou */
/* Vriskoume poio exei tin megaliteri periektikotita */
ore = getMaxAmount(ground);
if (ore == 0)
{
amount = ground[getX()][getY()].getPalladium();
}
else if (ore == 1)
{
amount = ground[getX()][getY()].getIridium();
}
else if (ore == 2)
{
amount = ground[getX()][getY()].getPlatinum();
}
/* An i periektikotita einai < 5 den aksizei na ginei eksoriksi */
if (amount < 5)
{
return;
}
/* Elegxoume an exei kseperasei to megisto fortio tou */
if (getMineCargo() + amount <= getMaxCargo())
{
if (ore == 0)
{
this->setPalladiumCargo(getPalladiumCargo() + amount); /* Auksanoume to fortio palladiou */
ground[getX()][getY()].setPalladium(0); /* Midenizoume tin periektikotita palladiou tis sigkekrimenis perioxis */
cout << "To robot " << getID() << " ekane eksoriksi : " << amount << " palladiou" << endl;
}
else if (ore == 1)
{
this->setIridiumCargo(getIridiumCargo() + amount);
ground[getX()][getY()].setIridium(0);
cout << "To robot " << getID() << " ekane eksoriksi : " << amount << " iridiou" << endl;
}
else if (ore == 2)
{
this->setPlatinumCargo(getPlatinumCargo() + amount);
ground[getX()][getY()].setPlatinum(0);
cout << "To robot " << getID() << " ekane eksoriksi : " << amount << " leukoxrusou" << endl;
}
checkForMineDamage(); /* Afou egine i eksoruksi, elenxoume an dimiourgithike vlavi */
if (isMineDamaged())
{
setState(true); /* An dimiourgithike thetoume tin katastasi tou ws TRUE - pou simanei vlavi */
}
setMineCargo(getMineCargo() + amount);
setTotalCargo(getTotalCargo() + amount);
totalMinedCargo += amount;
}
else
{
/* Elenxoume poia thesi gurw apo tin vasi einai adeia prokeimenou
na metaferthei ekei kai na metaferei ta sustatika */
// TODO : An einai gemates oles oi theseis, then what?
if (map->isEmpty(4, 5))
{
map->setPositions(getX(), getY(), "00");
setX(4);
setY(5);
map->setPositions(4, 5, getID());
}
else if (map->isEmpty(5, 6))
{
map->setPositions(getX(), getY(), "00");
setX(5);
setY(6);
map->setPositions(5, 6, getID());
}
else if (map->isEmpty(5, 4))
{
map->setPositions(getX(), getY(), "00");
setX(5);
setY(4);
map->setPositions(5, 4, getID());
}
else if (map->isEmpty(6, 5))
{
map->setPositions(getX(), getY(), "00");
setX(6);
setY(5);
map->setPositions(6, 5, getID());
}
else if (map->isEmpty(4, 6))
{
map->setPositions(getX(), getY(), "00");
setX(4);
setY(6);
map->setPositions(4, 6, getID());
}
else if (map->isEmpty(4, 4))
{
map->setPositions(getX(), getY(), "00");
setX(4);
setY(4);
map->setPositions(4, 4, getID());
}
else if (map->isEmpty(6, 4))
{
map->setPositions(getX(), getY(), "00");
setX(6);
setY(4);
map->setPositions(6, 4, getID());
}
else if (map->isEmpty(6, 6))
{
map->setPositions(getX(), getY(), "00");
setX(6);
setY(6);
map->setPositions(6, 6, getID());
}
setMineCargo(0);
counter = 1;
transfer(base);
}
}
void Analyser::move(Map * map)
{
int move;
bool flag = false;
// 1 - aristera
// 2 - deksia
// 3 - katw
// 4 - panw
// 5 - panw aristera
// 6 - panw deksia
// 7 - katw aristera
// 8 - katw deksia
/* Otan epistrepsei sti vasi den prpei n kinithei kateutheian alla na paramenei ekei gia 1 guro */
if (counter == 1)
{
counter = 0;
return;
}
while (!flag)
{
move = 1 + rand() % 8;
//cout << "Random A = " << move << endl;
if (move == 1)
{
//elegxos gia ektos oriwn
if ((getY() - 1 < 0) || (!map->isEmpty(getX(), getY() - 1))
|| (map->isFlag(getX(), getY() - 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setY(getY() - 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike aristera " << endl;
}
}
else if (move == 2)
{
if ((getY() + 1 >= map->getSize()) || (!map->isEmpty(getX(), getY() + 1))
|| (map->isFlag(getX(), getY() + 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setY(getY() + 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike deksia " << endl;
}
}
else if (move == 3)
{
if ((getX() + 1 >= map->getSize()) || (!map->isEmpty(getX() + 1, getY()))
|| (map->isFlag(getX() + 1, getY())))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() + 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike katw" << endl;
}
}
else if (move == 4)
{
if ((getX() - 1 < 0) || (!map->isEmpty(getX() - 1, getY()))
|| (map->isFlag(getX() - 1, getY())))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() - 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike panw " << endl;
}
}
else if (move == 5)
{
if ((getX() - 1 < 0) || (getY() - 1 < 0) || (!map->isEmpty(getX() - 1, getY() - 1))
|| (map->isFlag(getX() - 1, getY() - 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() - 1);
setY(getY() - 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike panw aristera " << endl;
}
}
else if (move == 6)
{
if ((getX() - 1 < 0) || (getY() + 1 >= map->getSize()) || (!map->isEmpty(getX() - 1, getY() + 1))
|| (map->isFlag(getX() - 1, getY() + 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() - 1);
setY(getY() + 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike panw deksia" << endl;
}
}
else if (move == 7)
{
if ((getX() + 1 >= map->getSize()) || (getY() - 1 < 0) || (!map->isEmpty(getX() + 1, getY() - 1))
|| (map->isFlag(getX() + 1, getY() - 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() + 1);
setY(getY() - 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike katw aristera " << endl;
}
}
else if (move == 8)
{
if ((getX() + 1 >= map->getSize()) || (getY() + 1 >= map->getSize()) || (!map->isEmpty(getX() + 1, getY() + 1))
|| (map->isFlag(getX() + 1, getY() + 1)))
{
continue;
}
else
{
map->setPositions(getX(), getY(), "00");
setX(getX() + 1);
setY(getY() + 1);
map->setPositions(getX(), getY(), getID());
flag = true;
setMoveCount(getMoveCount() + 1);
cout << "To robot " << getID() << " metakinithike katw deksia " << endl;
}
}
}
}
void Analyser::transfer(Base * base)
{
base->setPalladium(base->getPalladium() + this->getPalladiumCargo());
base->setIridium(base->getIridium() + this->getIridiumCargo());
base->setPlatinum(base->getPlatinum() + this->getPlatinumCargo());
/* Midenismos twrinou fortiou afou metaferthike idi sti vasi */
this->setPalladiumCargo(0);
this->setIridiumCargo(0);
this->setPlatinumCargo(0);
}
void Analyser::printInfo()
{
cout << "Robot ID = " << getID() << endl;
cout << "Katastasi = " << getState() << endl;
cout << "Ikanotita Prosvasis = " << getAccessAbility() << endl;
cout << "Sintetagmeni X = " << getX() << endl;
cout << "Sintetagmeni Y = " << getY() << endl;
cout << "Typos robot = " << getType() << endl;
cout << "Arithmos kinisewn = " << getMoveCount() << endl;
cout << "Arithmos vlavewn = " << getDamageCount() << endl;
cout << "Megisto Fortio = " << getMaxCargo() << endl;
cout << "Fortio pou exei eksoruksei mexri stigmis = " << getMineCargo() << endl;
cout << "Fortio pou exei eksoruksei sunolika afto to robot = " << getTotalCargo() << endl;
} | [
"johnbaris13@gmail.com"
] | johnbaris13@gmail.com |
810a20f7eb5af78fcd44eb47ad6cca374f7b44db | d87e41b60e0c524231642943b5c5834fb68fb2f9 | /scheduler.cpp | fd0d30b5370a345c4e0dc1f716ce421aa95e4aa3 | [
"MIT"
] | permissive | getopenmono/pong | 15073758cd25d1be73278e3f2fdd2164cc57d8a6 | f0b111bd9d24aff998e41243d333989455246520 | refs/heads/master | 2021-01-19T00:41:27.349448 | 2017-07-18T11:25:43 | 2017-07-18T11:25:43 | 87,201,412 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 463 | cpp | // This software is part of OpenMono, see http://developer.openmono.com
// Released under the MIT license, see LICENSE.txt
#include "scheduler.hpp"
Scheduler::Scheduler ()
{
}
void Scheduler::add (ITickable * tickable)
{
tickables.push_back(tickable);
}
void Scheduler::run (SharedState & state)
{
state.game = state.nextGameState;
for (std::vector<ITickable*>::iterator i = tickables.begin(); i != tickables.end(); ++i)
{
(*i)->tick(state);
}
}
| [
"jp@openmono.com"
] | jp@openmono.com |
121885baea7b8cbbeff0ab46a2043de8e63ce895 | 09ecab78e3bb904280e6d84663767fc9d2fabe86 | /Visual Studio/C++/GlobalWarning/GlobalWarming/GlobalWarming/Door.h | 2c857cb6c3cbafac606d306720ac56242e1b3253 | [] | no_license | HeroesOfBinary/ZombieElias | 73adad1459a77e796ea169ee83c1f93f92e94fe8 | 3e4e727f8c8d3e2e6b274ed663b6883307d7389d | refs/heads/master | 2016-09-03T07:25:25.241919 | 2014-09-07T21:42:07 | 2014-09-07T21:42:07 | 14,606,305 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 82 | h | #pragma once
#include "PreCompile.h"
class Door
{
public:
Door();
~Door();
};
| [
"heroesofbinary@gmail.com"
] | heroesofbinary@gmail.com |
9ba5906c30bceba26452738ceb6b8fb952b2aefd | 84cc4580e5bb8dda365932e31ec20ca45702f970 | /Spike07/Spike07/Spike07/BasicCommand.cpp | d2934adfab7bb04feacb6e93f72ed81710ed52d5 | [] | no_license | PubFork/gp-code | e21573b3dc5dd580ee6cc078336e5031ae4e932f | e7b7e1cd785afd58fe7e6e0d58293608c11c60e3 | refs/heads/master | 2020-07-08T16:36:03.620807 | 2016-11-07T10:45:44 | 2016-11-07T10:45:44 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 460 | cpp | #include "BasicCommand.h"
using namespace std;
using namespace placeholders;
GameState* BasicCommand::wrapper(const vector<string>& args) {
return _cmd();
}
BasicCommand::BasicCommand(GameState::PureCommand cmd) : Command() {
set_command(cmd);
}
BasicCommand::BasicCommand() : Command() {
}
BasicCommand::~BasicCommand() {
}
void BasicCommand::set_command(GameState::PureCommand cmd) {
_cmd = cmd;
add_overload(0,bind(&BasicCommand::wrapper,this,_1));
}
| [
"jtunaley@gmail.com"
] | jtunaley@gmail.com |
38239145d2438ca63c80a8bae76ea8de9ee425cb | 2a88b58673d0314ed00e37ab7329ab0bbddd3bdc | /blazetest/src/mathtest/dmatdmatmult/DDaMDa.cpp | 5a4f89d0f6e93d9a0b207cfe1c4b6e1e52648bff | [
"BSD-3-Clause"
] | permissive | shiver/blaze-lib | 3083de9600a66a586e73166e105585a954e324ea | 824925ed21faf82bb6edc48da89d3c84b8246cbf | refs/heads/master | 2020-09-05T23:00:34.583144 | 2016-08-24T03:55:17 | 2016-08-24T03:55:17 | 66,765,250 | 2 | 1 | NOASSERTION | 2020-04-06T05:02:41 | 2016-08-28T11:43:51 | C++ | UTF-8 | C++ | false | false | 4,342 | cpp | //=================================================================================================
/*!
// \file src/mathtest/dmatdmatmult/DDaMDa.cpp
// \brief Source file for the DDaMDa dense matrix/dense matrix multiplication math test
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cstdlib>
#include <iostream>
#include <blaze/math/DiagonalMatrix.h>
#include <blaze/math/DynamicMatrix.h>
#include <blazetest/mathtest/Creator.h>
#include <blazetest/mathtest/dmatdmatmult/OperationTest.h>
#include <blazetest/system/MathTest.h>
//=================================================================================================
//
// MAIN FUNCTION
//
//=================================================================================================
//*************************************************************************************************
int main()
{
std::cout << " Running 'DDaMDa'..." << std::endl;
using blazetest::mathtest::TypeA;
try
{
// Matrix type definitions
typedef blaze::DiagonalMatrix< blaze::DynamicMatrix<TypeA> > DDa;
typedef blaze::DynamicMatrix<TypeA> MDa;
// Creator type definitions
typedef blazetest::Creator<DDa> CDDa;
typedef blazetest::Creator<MDa> CMDa;
// Running tests with small matrices
for( size_t i=0UL; i<=6UL; ++i ) {
for( size_t j=0UL; j<=6UL; ++j ) {
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( i ), CMDa( i, j ) );
}
}
// Running tests with large matrices
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 15UL ), CMDa( 15UL, 37UL ) );
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 37UL ), CMDa( 37UL, 37UL ) );
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 63UL ), CMDa( 63UL, 37UL ) );
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 16UL ), CMDa( 16UL, 32UL ) );
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 32UL ), CMDa( 32UL, 32UL ) );
RUN_DMATDMATMULT_OPERATION_TEST( CDDa( 64UL ), CMDa( 64UL, 32UL ) );
}
catch( std::exception& ex ) {
std::cerr << "\n\n ERROR DETECTED during dense matrix/dense matrix multiplication:\n"
<< ex.what() << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//*************************************************************************************************
| [
"klaus.iglberger@gmail.com"
] | klaus.iglberger@gmail.com |
a6d13d7ab0bbee3ce153f85c593dfb5517448314 | 8db3dfa3e15437e8cd7715bb76b7540d755846f3 | /src/sx_film_classifica.cpp | 581d08e0d4ddc05993e58709aad472a50d2e0dd1 | [
"MIT"
] | permissive | D33pBlue/Cinenote-3.0 | 0b39e8f4f54fae524efb00fd1c1483844075acfd | 7dd871b40c537fdf73e7489919c4bfef391864c2 | refs/heads/master | 2020-03-09T16:50:55.667849 | 2018-04-11T11:07:11 | 2018-04-11T11:07:11 | 128,895,531 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,524 | cpp | #include "sx_film_classifica.h"
#include "dialog_info_film.h"
sx_film_classifica::sx_film_classifica(QWidget *parent) :
QWidget(parent)
{
lay=new QVBoxLayout;
tit=new QLabel("Classifica film migliori");
tit->setFont(QFont("Times",20));
lay->addWidget(tit);
tab=new QTableWidget;
tab->setColumnCount(3);
tab->setHorizontalHeaderLabels(QStringList()<<"Posizione"<<"Film"<<"id");
tab->setColumnWidth(1,400);
lay->addWidget(tab);
QSqlQuery q;
q.exec("select c.posizione,f.titolo,c.film from classifica as c join film as f on c.film=f.id order by c.posizione;");
while(q.next()){
tab->insertRow(tab->rowCount());
QTableWidgetItem *e1=new QTableWidgetItem(q.value(0).toString());
QTableWidgetItem *e2=new QTableWidgetItem(q.value(1).toString());
QTableWidgetItem *e3=new QTableWidgetItem(q.value(2).toString());
eltab.push_back(e1);
eltab.push_back(e2);
eltab.push_back(e3);
tab->setItem(tab->rowCount()-1,0,e1);
tab->setItem(tab->rowCount()-1,1,e2);
tab->setItem(tab->rowCount()-1,2,e3);
}
connect(tab,SIGNAL(cellClicked(int,int)),this,SLOT(vediFilm(int,int)));
setLayout(lay);
}
sx_film_classifica::~sx_film_classifica(){
for(int i=0;i<eltab.size();i++) delete eltab[i];
delete tab;
delete tit;
delete lay;
}
void sx_film_classifica::vediFilm(int r, int c){
Dialog_info_film* info=new Dialog_info_film(tab->item(r,2)->text().toInt(),this);
info->show();
}
| [
"francescob994@protonmail.com"
] | francescob994@protonmail.com |
6b551dae43eaeba48ca78725a3d14c8fb2bc2da5 | e908f7546ebbdb7f03a007295c4521063b6b8855 | /RJ/GameVarsExtern.cpp | b324190c75ea76a8ade762fa5c9b6cb7d9ef8e83 | [] | no_license | RobJenks/rj-engine | 6c1fd8bf6e9892fa02b6834a012e7a2d732fadf9 | b3ae7c977d149b7ce6fd406e80b0693705226f17 | refs/heads/master | 2022-12-25T03:09:51.260463 | 2020-10-04T16:21:49 | 2020-10-04T16:21:49 | 301,125,778 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 24,844 | cpp | #include <vector>
#include <unordered_map>
#include "DX11_Core.h"
#include "time.h"
#include "RJMain.h"
#include "Ship.h"
#include "Actor.h"
#include "GameInput.h"
#include "CentralScheduler.h"
#include "GamePhysicsEngine.h"
#include "SimulationStateManager.h"
#include "FactionManagerObject.h"
#include "LogManager.h"
#include "GameConsole.h"
#include "DebugCommandHandler.h"
class CoreEngine;
class Player;
#include "GameVarsExtern.h"
#ifndef __GameVarsExtern_Types_H__
#define __GameVarsExtern_Types_H__
namespace Game {
typedef unsigned int ID_TYPE;
typedef float HitPoints;
};
#endif
namespace Game {
// Main application instance
RJMain Application;
std::string ExeName = "";
std::string ExePath = "";
// The core game engine
CoreEngine *Engine = NULL;
// Gameplay settings
static const float GameSpeed = 1.0f; // Game speed multiplier, applied to every frame
MouseInputControlMode MouseControlMode = MouseInputControlMode::MC_MOUSE_FLIGHT;
// Persistent timers, that progress regardless of the state of the game simulation
float PersistentClockTime = 0.0f; // Time (secs)
float PersistentTimeFactor = 0.0001f; // Time (secs) passed since the previous frame
XMVECTOR PersistentTimeFactorV = XMVectorReplicate(PersistentTimeFactor); // Time (secs) passed since the previous frame (vectorised form)
unsigned int PersistentClockMs = 0U; // System time (ms)
unsigned int PreviousPersistentClockMs = 0U; // System time (ms) on the previous cycle
unsigned int PersistentClockDelta = 0U; // Delta time (ms) since the previous frame
// Game timers, that stop and start as the game pause state is changed
float ClockTime = 0.0f; // Time (secs)
float TimeFactor = 0.0001f; // Time (secs) passed since the previous frame
XMVECTOR TimeFactorV = XMVectorReplicate(TimeFactor); // Time (secs) passed since the previous frame (vectorised form)
unsigned int ClockMs = 0U; // System time (ms)
unsigned int PreviousClockMs = 0U; // System time (ms) on the previous cycle
unsigned int ClockDelta = 0U; // Delta time (ms) since the previous frame
// FPS and performance data
float FPS = 0.0f;
bool FPSDisplay = true;
long FrameIndex = 0L;
// Display settings; default values that will be overwritten by game config on load
int ScreenWidth = 1024;
int ScreenHeight = 768;
int ScreenRefresh = 0;
INTVECTOR2 ScreenCentre = INTVECTOR2(Game::ScreenWidth / 2, Game::ScreenHeight / 2);
INTVECTOR2 FullWindowSize = NULL_INTVECTOR2;
INTVECTOR2 WindowPosition = NULL_INTVECTOR2;
float FOV = (PI / 4.0f);
float NearClipPlane = Game::C_DEFAULT_CLIP_NEAR_DISTANCE;
float FarClipPlane = Game::C_DEFAULT_CLIP_FAR_DISTANCE;
bool FullScreen = false;
bool VSync = true; // TODO: Render output is flickering when vsync == false, need to determine why
bool ForceWARPRenderDevice = false;
// Indicates whether the primary data load & initialisation process has been completed on startup
bool GameDataLoaded = false;
// Central scheduler for all scheduled jobs
CentralScheduler Scheduler = CentralScheduler();
// State manager, which maintains the simulation state and level for all objects/systems/processes in the game
SimulationStateManager StateManager = SimulationStateManager();
// Faction manager, which maintains the central record of all faction and the relationships between them
FactionManagerObject FactionManager = FactionManagerObject();
// The game console, which processes all incoming console commands
GameConsole Console = GameConsole();
DebugCommandHandler DebugCommandManager = DebugCommandHandler();
// Central components used to periodically prune all spatial partitioning trees to remove redundant nodes
//OctreePruner<iSpaceObject*> TreePruner = OctreePruner<iSpaceObject*>();
// Collision manager, which performs all collision detection and response determination each cycle
GamePhysicsEngine PhysicsEngine = GamePhysicsEngine();
// The game universe
GameUniverse * Universe;
// Player data
Player * CurrentPlayer = NULL; // Pointer to the current player
// Primary input controllers for the application
GameInputDevice Keyboard;
GameInputDevice Mouse;
// Global flag indicating whether the application is paused
bool Paused = false;
// Global flags indicating whether the application has focus this frame, and the actions to take on focus change
bool HasFocus = false;
bool PauseOnLoseFocus = false;
bool CaptureKeyboardWithoutFocus = false;
bool CaptureMouseWithoutFocus = false;
// System constants
const clock_t C_SECONDS_PER_CLOCK = (const clock_t)1.0 / (const clock_t)CLOCKS_PER_SEC;
// General application constants
unsigned int C_MAX_FRAME_DELTA = 200; // Maximum frame delta of 200ms (= minimum 5 FPS)
// File input/output constants
const int C_DATA_LOAD_RECURSION_LIMIT = 50; // Maximum recursion depth when loading data files, to prevent infinite loops
const int C_CONFIG_LOAD_RECURSION_LIMIT = 25; // Maximum recursion depth when loading config files, to prevent infinite loops
// Rendering constants
const bool C_RENDER_DEBUG_LAYER = true; // Flag indicating whether we should attempt to load a debug layer for the current rendering
// engine (e.g D3D_DEVICE_DEBUG). Only available in debug builds regardless of the state of this flag
const size_t C_INSTANCED_RENDER_LIMIT = 1000U; // The maximum number of instances that can be rendered in any one draw call by the engine
const float C_MODEL_SIZE_LIMIT = 10000.0f; // The maximum size of any model; prevents overflow / accidental scaling to unreasonble values
const int C_MAX_ARTICULATED_MODEL_SIZE = 128; // The maximum number of components within any articulated model
const unsigned int C_DEFAULT_RENDERQUEUE_CHECK_INTERVAL = 1000U; // Time (ms) between pre-optimisation checks of the render queue
const unsigned int C_DEFAULT_RENDERQUEUE_OPTIMISE_INTERVAL = 10000U; // Time (ms) between optimisation passes on the render queue
const float C_LIGHT_RENDER_DISTANCE = 10000.0f; // The maximum distance at which lights are considered during rendering
const size_t C_MAX_PORTAL_RENDERING_DEPTH = 16U; // Maximum number of cell traversals we allow in any particular portal rendering branch
// Physics constants
const float C_EPSILON = 1e-6f;
const float C_EPSILON_NEG = (-C_EPSILON);
const XMVECTOR C_EPSILON_V = XMVectorReplicate(C_EPSILON);
const XMVECTOR C_EPSILON_NEG_V = XMVectorReplicate(C_EPSILON_NEG);
const double C_EPSILON_DP = (double)C_EPSILON;
const float C_LARGE_FLOAT = 1e15;
const float C_MIN_PHYSICS_CYCLES_PER_SEC = 30.0f; // The minimum number of physics cycles that should be run per
// second (i.e. the physics FPS)
const float C_MAX_PHYSICS_TIME_DELTA = (1.0f / C_MIN_PHYSICS_CYCLES_PER_SEC); // The maximum permitted physics time delta, beyond which multiple
// cycles will be run per frame
const float C_MAX_PHYSICS_FRAME_CYCLES = 5.0f; // The maximum number of phyiscs cycles permitted per render
// frame, to avoid the 'spiral-of-death'
const float C_MOMENTUM_DAMPING_THRESHOLD = 0.001f; // Momentum in each direction will be damped to zero if it is below this threshold
const XMVECTOR C_MOMENTUM_DAMPING_THRESHOLD_V = XMVectorReplicate(C_MOMENTUM_DAMPING_THRESHOLD);
float C_MOVEMENT_DRAG_FACTOR = 0.025f;
float C_ENGINE_SIMULATION_UPDATE_INTERVAL = 0.1f; // Interval (secs) between updates of the engine simulation
bool C_NO_MOMENTUM_LIMIT = false; // Determines whether the momentum safety limit is enabled
float C_ANGULAR_VELOCITY_DAMPING_FACTOR = 0.01f; // Damping applied to angular rotation, measured in rad/sec
float C_COLLISION_SPACE_COEFF_ELASTICITY = 0.9f; // Coefficient of elasticity for space-based collisions
AXMVECTOR C_COLLISION_SPACE_COEFF_ELASTICITY_V = XMVectorReplicate(C_COLLISION_SPACE_COEFF_ELASTICITY);
float C_MAX_LINEAR_VELOCITY = 10000.0f; // Max linear velocity that any object can attain; to avoid overflows and other physics-based errors
float C_MAX_ANGULAR_VELOCITY = 10.0f; // Max angular velocity that any object can attain; to avoid overflows and other physics-based errors
float C_ENVIRONMENT_MOVE_DRAG_FACTOR = 4.0f; // The amount of x/z velocity that is lost by environment objects per second due to 'friction'
float C_OBJECT_FAST_MOVER_THRESHOLD = 0.75f; // The percentage of an object's extent that it has to move per frame to qualify as a "fast mover"
const int C_MAX_INTRA_FRAME_CCD_COLLISIONS = 5; // The maximum number of CCD collisions we support WITHIN a frame (e.g. multiple very fast ricochets)
float C_PROJECTILE_VELOCITY_LIMIT = 5000.0f; // Implement a universal limit (m/sec) on the velocity of projectiles, to avoid unexpectedly large calculated velocity
float C_PROJECTILE_VELOCITY_LIMIT_SQ =
C_PROJECTILE_VELOCITY_LIMIT * C_PROJECTILE_VELOCITY_LIMIT; // Squared universal velocity limit (m/sec) for projectiles
// Collision-detection constants
const float C_ACTIVE_COLLISION_DISTANCE_SHIPLEVEL = 5000.0f; // Distance within which collision detection is performed (in a ship context)
const float C_ACTIVE_COLLISION_DISTANCE_ACTORLEVEL = 40.0f; // Distance within which collision detection is performed (in an actor context)
const float C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD = 1.0f; // Threshold momentum value, above which we apply an additional collision response
const float C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD_SQ = // Squared threshold momentum value, above which
C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD * C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD; // we apply an additional collision response
const AXMVECTOR C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD_V = XMVectorReplicate(C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD);
const AXMVECTOR C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD_SQ_V = XMVectorReplicate(C_ENVIRONMENT_COLLISION_RESPONSE_THRESHOLD_SQ);
const float C_VERTICAL_COLLISION_SNAP_DISTANCE = 0.01f; // Distance at which a slowly-moving object falling into terrain will snap to it and arrest its local vertical momentum
const int C_MAX_OBJECT_COLLISION_EXCLUSIONS = 256; // The maximum number of collision exclusions that can be applied to an object
const unsigned int C_STATIC_PAIR_CD_INTERVAL = 1000U; // The interval (ms) between 'full' collision detection checks, where we also include static/static pairs
const float C_CONSTANT_COLLISION_AVOIDANCE_RANGE_MULTIPLIER = 2.5f; // Constant multiplier applied to collision range when performing collision avoidance
const float C_COLLISION_AVOIDANCE_RESPONSE_SAFETY_MULTIPLIER = 1.25f; // Safety multiplier on the minimum required response to avoid a collision
const float C_OBB_SIZE_THRESHOLD = 25.0f; // The size at which we begin considering OBB as a better alternative to bounding sphere for the object
const float C_OBB_SIZE_RATIO_THRESHOLD = 2.0f; // The size ratio at which we begin using OBB rather than bounding sphere (for large objects), due to better accuracy
const float C_GROUND_COLLISION_STEP_THRESHOLD = 0.2f; // The max size of 'step' that an object will traverse when moving along a horizontal surface
const float C_GROUND_COLLISION_STEP_THRESHOLD_HALF = C_GROUND_COLLISION_STEP_THRESHOLD * 0.5f; // Half of the constant step threshold for ground traversal
// Object management constants
const int C_OCTREE_MAX_NODE_ITEMS = 12; // The target object limit per octree node; can be overriden if required
// based on current node size
const float C_OCTREE_MIN_NODE_SIZE = 250.0f; // Minimum acceptable octree node size. Overrides node count limit if required
const int C_ENVTREE_MAX_NODE_ITEMS = 12; // Target total object limit per envtree node; can be overriden if required
// based on current node size
const int C_ENVTREE_MIN_NODE_SIZE = 1; // Minimum acceptanble envtree node size, in elements. Overrides node count
// limit if required
const INTVECTOR3 C_ENVTREE_MIN_NODE_SIZE_V // Vectorised form; minimum acceptable node size, in elements
= INTVECTOR3(C_ENVTREE_MIN_NODE_SIZE);
const int C_ENVTREE_MAX_NODE_ITEMS_PER_TYPE // Max node items per category (e.g. objects, terrain)
= C_ENVTREE_MAX_NODE_ITEMS / 2;
const float C_ENVIRONMENT_OBJECT_SEARCH_DISTANCE_MARGIN = 25.0f; // Additional threshold used when finding objects to be tested in proximity calculations
const unsigned int C_ENVIRONMENT_VISIBLE_TERRAIN_QUERY_VALIDITY_PERIOD = 100U; // Period of time (ms) in which the result of an environment visible terrain query remain valid
// Camera-related constants
float C_DEFAULT_CLIP_NEAR_DISTANCE = 1.0f; // Default world-unit distance for the near clip plane
float C_DEFAULT_CLIP_FAR_DISTANCE = 1000.0f; // Default world-unit distance for the far clip plane
float C_DEFAULT_ZOOM_TO_SHIP_SPEED = 1.75f; // Default number of seconds to zoom the camera from its current location to a ship
float C_DEFAULT_ZOOM_TO_SHIP_OVERHEAD_DISTANCE = 75.0f; // Default distance to place the camera above a ship, if it cannot be determined any other way
float C_DEBUG_CAMERA_SPEED = 500.0f; // The movement speed of the debug camera
float C_DEBUG_CAMERA_TURN_SPEED = 100.0f; // The turn speed of the debug camera
float C_DEBUG_CAMERA_FAST_MOVE_MODIFIER = 10.0f; // Modifier to debug camera move speed when fast-travel key is held
float C_DEBUG_CAMERA_SLOW_MOVE_MODIFIER = 0.1f; // Modifier to debug camera move speed when slow-travel key is held
float C_DEBUG_CAMERA_ROLL_SPEED = 2.0f; // The speed at which the debug camera will revert its roll component
// Player-related contants
const float C_PLAYER_MOUSE_TURN_MODIFIER_YAW = 20.0f; // Modifier to yaw speed (about Y) when using the mouse, i.e. the mouse sensitivity
const float C_PLAYER_MOUSE_TURN_MODIFIER_PITCH = 30.0f; // Modifier to pitch speed (about X) when using the mouse, i.e. the mouse sensitivity
const float C_PLAYER_PITCH_MIN = PI * -0.4f; // Minimum possible pitch of the player view (i.e. furthest extent we can look down)
const float C_PLAYER_PITCH_MAX = PI * 0.4f; // Maximum possible pitch of the player view (i.e. furthest extent we can look up)
const float C_THRUST_INCREMENT_PC = 0.2f; // Percentage of total thrust range that will be incremented/decremented by player throttle each second
const float C_MOUSE_FLIGHT_MULTIPLIER = 1.0f; // Multiplier to avoid mouse flight requiring the full screen bounds to achieve min/max turning
const float C_PLAYER_USE_DISTANCE = 6.0f; // Distance within which the player can activate a UsableObject
const XMVECTOR C_PLAYER_USE_DISTANCE_V
= XMVectorReplicate(C_PLAYER_USE_DISTANCE); // Vectorised distance within which the player can activate a UsableObject
const float C_PLAYER_USE_DISTANCE_SQ
= C_PLAYER_USE_DISTANCE * C_PLAYER_USE_DISTANCE; // Squared distance within which the player can activate a UsableObject
const XMVECTOR C_PLAYER_USE_DISTANCE_SQ_V
= XMVectorReplicate(C_PLAYER_USE_DISTANCE_SQ); // Vectorised squared distance within which the player can activate a UsableObject
// Ship simulation, movement and manuevering constants
float C_AI_DEFAULT_TURN_MODIFIER_PEACEFUL = 0.7f; // Default turn modifier for ships when not in combat. Can be overidden per ship/pilot
float C_AI_DEFAULT_TURN_MODIFIER_COMBAT = 1.0f; // Default turn modifier for ships when in combat. Can be overidden per ship/pilot
float C_DEFAULT_SHIP_CONTACT_ANALYSIS_RANGE = 20000.0f; // The default range within which ships will analyse nearby contacts
unsigned int C_DEFAULT_SHIP_CONTACT_ANALYSIS_FREQ = 3000U; // Default interval between analysis of nearby contacts (ms)
// Immediate Region-related data
float C_IREGION_BOUNDS = 150.0f; // The maximum bounds in each direction that we will extend the immediate region
float C_IREGION_MIN = 10.0f; // Min bounds for the I-Region, within which we will not create new particles
float C_IREGION_THRESHOLD = 25.0f; // Update threshold for the I-Region
float C_DUST_PARTICLE_BLEND_RATE = 0.25f; // The percentage of total colour blended in each second as particles are created
// Complex ship constants
float C_CS_ELEMENT_SCALE = 10.0f; // The physical size of each CS element in space
float C_CS_ELEMENT_MIDPOINT = C_CS_ELEMENT_SCALE * 0.5f; // Midpoint of an element in each dimension
float C_CS_ELEMENT_SCALE_RECIP = (1.0f / C_CS_ELEMENT_SCALE); // Reciprocal of the element scale (1.0f/scale)
XMVECTOR C_CS_ELEMENT_SCALE_V = XMVectorReplicate(C_CS_ELEMENT_SCALE); // The physical size of each CS element in space (replicated vector form)
XMVECTOR C_CS_ELEMENT_MIDPOINT_V = XMVectorReplicate(C_CS_ELEMENT_MIDPOINT); // Midpoint of an element in each dimension (replicated vector form)
XMVECTOR C_CS_ELEMENT_SCALE_RECIP_V = XMVectorReplicate(C_CS_ELEMENT_SCALE_RECIP); // Reiprocal of the element scale (1.0f/scale) (replicated vector form)
float C_CS_ELEMENT_EXTENT = C_CS_ELEMENT_MIDPOINT; // Extent (centre-to-edge) of an element in each dimension
XMVECTOR C_CS_ELEMENT_EXTENT_V = XMVectorReplicate(C_CS_ELEMENT_EXTENT); // Extent (centre-to-edge) of an element in each dimension (replicated vector form)
XMVECTOR C_CS_ELEMENT_SCALE_NEG_V = XMVectorNegate(C_CS_ELEMENT_SCALE_V); // Negation of the element scale (replicated vector form)
XMVECTOR C_CS_ELEMENT_MIDPOINT_NEG_V = XMVectorNegate(C_CS_ELEMENT_MIDPOINT_V); // Negation of the element midpoint (replicated vector form)
XMVECTOR C_CS_ELEMENT_EXTENT_NEG_V = XMVectorNegate(C_CS_ELEMENT_EXTENT_V); // Negation of the element extent (replicated vector form)
int C_CS_ELEMENT_SIZE_LIMIT = (500 * 500 * 100); // Maximum element count for any complex ship element environment
float C_CS_PERIMETER_BEACON_FREQUENCY = 400.0f; // The (approx, max) spacing between perimeter beacons on a capital ship
XMVECTOR C_CS_PERIMETER_BEACON_FREQUENCY_V =
XMVectorReplicate(C_CS_PERIMETER_BEACON_FREQUENCY); // The (approx, max) spacing between perimeter beacons on a capital ship (vectorised)
// AI, order management and ship computer constants
unsigned int C_DEFAULT_ENTITY_AI_EVAL_INTERVAL = 3000U; // The default interval for evaluation of current situation by an entity AI
unsigned int C_DEFAULT_FLIGHT_COMPUTER_EVAL_INTERVAL = 100U; // The default interval for evaluation by the ship flight computer
unsigned int C_DEFAULT_ORDER_EVAL_FREQUENCY = 500U; // The default interval for subsequent evaluations of an order by the AI
unsigned int C_DEFAULT_ORDER_QUEUE_MAINTENANCE_FREQUENCY = 5000U; // Default interval for entity maintenance of its order queue
float C_ENGINE_THRUST_DECREASE_THRESHOLD = 0.9f; // % threshold of target speed at which we start to reduce engine thrust
float C_DEFAULT_ATTACK_CLOSE_TIME = 2.5f; // Close distance will be this many seconds at full velocity from target
float C_DEFAULT_ATTACK_CLOSE_RADIUS_MULTIPLIER = 1.5f; // Multiple of target collision sphere radius that we will account for when attacking, by default
float C_DEFAULT_ATTACK_RETREAT_TIME = 2.5f; // Retreat distance between attack runs will be this many seconds at full velocity, added to close dist
float C_ATTACK_TAIL_FOLLOW_THRESHOLD = 0.75f; // We will attempt to get 'on the tail' of ships travelling more than (this) % of our velocity limit
float C_DEFAULT_FLEE_DISTANCE = 5000.0f; // Default distance we will attempt to flee from enemies, if in 'flee' mode
unsigned int C_TARGET_LEADING_RECALC_INTERVAL = 500U; // Ships will recalculate their target leading distance every interval (ms)
// Actor-related constants
float C_ACTOR_DEFAULT_RUN_SPEED = 18.0f; // Default run speed for all actors unless specified
float C_ACTOR_DEFAULT_WALK_MULTIPLIER = 0.5f; // Default multiplier to convert run speed to walk speed
float C_ACTOR_DEFAULT_STRAFE_MULTIPLIER = 0.75f; // Default multiplier to convert run speed to strafe speed
float C_ACTOR_DEFAULT_TURN_RATE = 5.0f; // Default turn rate in radians/sec
float C_ACTOR_DEFAULT_HEAD_BOB_SPEED = 1.5f; // Default speed of the player head bob when controlling an actor
float C_ACTOR_DEFAULT_HEAD_BOB_AMOUNT = 0.2f; // Default height that the player head bob will reach when controlling an actor
float C_ACTOR_DEFAULT_JUMP_STRENGTH = 1.0f; // Default jump strength, as a modifier relative to the actor mass (so resulting
// in a force of equal strength regardless of mass)
XMFLOAT3 C_ACTOR_DEFAULT_VIEW_OFFSET = XMFLOAT3(0.0f, 5.0f, 0.0f); // Default offset of the player view when controlling an actor,
// if not set directly by the actor
// Pathfinding constants
int C_CS_ELEMENT_MIDPOINT_INT = (int)C_CS_ELEMENT_MIDPOINT; // Integer rounded value for midpoint of an element (for efficiency)
int C_NAVNETWORK_TRAVERSE_COST = (int)C_CS_ELEMENT_SCALE; // Cost of moving from one element to another (non-diagonal)
int C_NAVNETWORK_TRAVERSE_COST_DIAG = (int)(C_CS_ELEMENT_SCALE * 1.41421356f); // Diagonal traversal cost; equal to normal cost * SQRT(2)
// Simulation constants
int C_SIMULATION_STATE_MANAGER_UPDATE_INTERVAL = 2000; // Interval between each evaluation of the state manager (ms)
float C_SPACE_SIMULATION_HUB_RADIUS = 5000.0f; // Distance within which objects are fully simulated by a hub
float C_SPACE_SIMULATION_HUB_RADIUS_SQ = C_SPACE_SIMULATION_HUB_RADIUS // Squared distance within which objects are fully simulated by a hub
* C_SPACE_SIMULATION_HUB_RADIUS;
AXMVECTOR C_SPACE_SIMULATION_HUB_RADIUS_SQ_V =
XMVectorReplicate(C_SPACE_SIMULATION_HUB_RADIUS_SQ); // Vectorised version of the sq distance within which objects are fully simulated by a hub
// Turret simulation and controller constants
float C_MIN_TURRET_RANGE = 1.0f; // Minimum distance within which a turret can fire at a target
float C_MAX_TURRET_RANGE = 100000.0f; // Maximum distance within which a turret can fire at a target
unsigned int C_PROJECTILE_OWNER_DETACH_PERIOD = 1000U; // Period within which a projectile is protected from colliding with its owner (ms)
int C_MAX_TURRET_LAUNCHERS = 128; // The maximum number of launchers that a single turret can hold
float C_DEFAULT_FIRING_REGION_THRESHOLD = 0.05f; // Deviation in pitch/yaw within which a turret will start firing at the target
float C_DEFAULT_FIRING_SPREAD_THRESHOLD = 5.0f; // Default multiple on weapon spread within which a turret will begin firing
// Debug constants
const float C_DEBUG_RENDER_ENVIRONMENT_COLLISION_BOX_RADIUS = 20.0f; // Radius within which debug collision boxes are rendered
// Default tile simulation values
unsigned int C_TILE_LIFESUPPORT_SIMULATION_INTERVAL = 250U; // Life support tiles will be simulated with this interval, when active
unsigned int C_TILE_POWERGENERATOR_SIMULATION_INTERVAL = 250U; // Power generator tiles will be simulated with this interval, when active
unsigned int C_TILE_ENGINEROOM_SIMULATION_INTERVAL = 200U; // Engine room tiles will be simulated with this interval, when active
// Translate collision mode values to/from their string representation
CollisionMode TranslateCollisionModeFromString(const std::string & mode)
{
std::string s = mode; StrLowerC(s);
if (mode == "fullcollision")
return CollisionMode::FullCollision;
else if (mode == "broadphasecollisiononly")
return CollisionMode::BroadphaseCollisionOnly;
else
return CollisionMode::NoCollision;
}
// Translate collision mode values to/from their string representation
std::string TranslateCollisionModeToString(CollisionMode mode)
{
switch (mode)
{
case CollisionMode::FullCollision: return "fullcollision";
case CollisionMode::BroadphaseCollisionOnly: return "broadphasecollisiononly";
default: return "nocollision";
}
}
// Translate collider type values to/from their string representation
ColliderType TranslateColliderTypeFromString(const std::string & type)
{
std::string s = type; StrLowerC(s);
if (s == "passivecollider")
return ColliderType::PassiveCollider;
else
return ColliderType::ActiveCollider;
}
// Translate collision mode values to/from their string representation
std::string TranslateColliderTypeToString(ColliderType type)
{
switch (type)
{
case ColliderType::PassiveCollider:
return "passivecollider"; break;
default:
return "activecollider"; break;
}
}
};
| [
"robjenks@gmail.com"
] | robjenks@gmail.com |
1cffcb97bf74f682e65920e14e760f5cd2e38a2e | 04b1803adb6653ecb7cb827c4f4aa616afacf629 | /third_party/blink/public/platform/platform.h | cd2e8603c391b1732abb8621ee41a2703ded6c39 | [
"LGPL-2.0-or-later",
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.1-only",
"GPL-1.0-or-later",
"GPL-2.0-only",
"LGPL-2.0-only",
"BSD-2-Clause",
"LicenseRef-scancode-other-copyleft",
"MIT",
"Apache-2.0",
"BSD-3-Clause"
] | permissive | Samsung/Castanets | 240d9338e097b75b3f669604315b06f7cf129d64 | 4896f732fc747dfdcfcbac3d442f2d2d42df264a | refs/heads/castanets_76_dev | 2023-08-31T09:01:04.744346 | 2021-07-30T04:56:25 | 2021-08-11T05:45:21 | 125,484,161 | 58 | 49 | BSD-3-Clause | 2022-10-16T19:31:26 | 2018-03-16T08:07:37 | null | UTF-8 | C++ | false | false | 28,286 | h | /*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_PLATFORM_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_PLATFORM_H_
#include <memory>
#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string_piece.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/blink/public/common/feature_policy/feature_policy.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/public/mojom/loader/code_cache.mojom-shared.h"
#include "third_party/blink/public/platform/blame_context.h"
#include "third_party/blink/public/platform/code_cache_loader.h"
#include "third_party/blink/public/platform/user_metrics_action.h"
#include "third_party/blink/public/platform/web_audio_device.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/public/platform/web_dedicated_worker_host_factory_client.h"
#include "third_party/blink/public/platform/web_gesture_device.h"
#include "third_party/blink/public/platform/web_localized_string.h"
#include "third_party/blink/public/platform/web_rtc_api_name.h"
#include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/public/platform/web_speech_synthesizer.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_loader.h"
#include "third_party/blink/public/platform/web_url_loader_factory.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace cricket {
class PortAllocator;
}
namespace gpu {
class GpuMemoryBufferManager;
}
namespace rtc {
class Thread;
}
namespace service_manager {
class Connector;
class InterfaceProvider;
}
namespace v8 {
class Context;
template <class T>
class Local;
}
namespace webrtc {
struct RtpCapabilities;
class AsyncResolverFactory;
}
namespace blink {
class InterfaceProvider;
class Thread;
struct ThreadCreationParams;
class WebAudioBus;
class WebAudioLatencyHint;
class WebBlobRegistry;
class WebCrypto;
class WebDatabaseObserver;
class WebDedicatedWorker;
class WebGraphicsContext3DProvider;
class WebLocalFrame;
class WebMediaCapabilitiesClient;
class WebMediaPlayer;
class WebMediaRecorderHandler;
class WebMediaStream;
class WebMediaStreamCenter;
class WebPrescientNetworking;
class WebPublicSuffixList;
class WebRTCCertificateGenerator;
class WebRTCPeerConnectionHandler;
class WebRTCPeerConnectionHandlerClient;
class WebSandboxSupport;
class WebSecurityOrigin;
class WebSpeechSynthesizer;
class WebSpeechSynthesizerClient;
class WebStorageNamespace;
class WebThemeEngine;
class WebTransmissionEncodingInfoHandler;
class WebURLLoaderMockFactory;
class WebURLResponse;
class WebURLResponse;
namespace scheduler {
class WebThreadScheduler;
}
class BLINK_PLATFORM_EXPORT Platform {
public:
// Initialize platform and wtf. If you need to initialize the entire Blink,
// you should use blink::Initialize. WebThreadScheduler must be owned by
// the embedder.
static void Initialize(Platform*,
scheduler::WebThreadScheduler* main_thread_scheduler);
static Platform* Current();
// This is another entry point for embedders that only require simple
// execution environment of Blink. This version automatically sets up Blink
// with a minimally viable implementation of WebThreadScheduler and
// blink::Thread for the main thread.
//
// TODO(yutak): Fix function name as it seems obsolete at this point.
static void CreateMainThreadAndInitialize(Platform*);
// Used to switch the current platform only for testing.
// You should not pass in a Platform object that is not fully instantiated.
static void SetCurrentPlatformForTesting(Platform*);
// This sets up a minimally viable implementation of blink::Thread without
// changing the current Platform. This is essentially a workaround for the
// initialization order in ScopedUnittestsEnvironmentSetup, and nobody else
// should use this.
static void CreateMainThreadForTesting();
// These are dirty workaround for tests requiring the main thread task runner
// from a non-main thread. If your test needs base::ScopedTaskEnvironment
// and a non-main thread may call MainThread()->GetTaskRunner(), call
// SetMainThreadTaskRunnerForTesting() in your test fixture's SetUp(), and
// call UnsetMainThreadTaskRunnerForTesting() in TearDown().
//
// TODO(yutak): Ideally, these should be packed in a custom test fixture
// along with ScopedTaskEnvironment for reusability.
static void SetMainThreadTaskRunnerForTesting();
static void UnsetMainThreadTaskRunnerForTesting();
Platform();
virtual ~Platform();
// May return null if sandbox support is not necessary
virtual WebSandboxSupport* GetSandboxSupport() { return nullptr; }
// May return null on some platforms.
virtual WebThemeEngine* ThemeEngine() { return nullptr; }
// May return null.
virtual std::unique_ptr<WebSpeechSynthesizer> CreateSpeechSynthesizer(
WebSpeechSynthesizerClient*) {
return nullptr;
}
// AppCache ----------------------------------------------------------
virtual bool IsURLSupportedForAppCache(const WebURL& url) { return false; }
// Audio --------------------------------------------------------------
virtual double AudioHardwareSampleRate() { return 0; }
virtual size_t AudioHardwareBufferSize() { return 0; }
virtual unsigned AudioHardwareOutputChannels() { return 0; }
// Creates a device for audio I/O.
// Pass in (number_of_input_channels > 0) if live/local audio input is
// desired.
virtual std::unique_ptr<WebAudioDevice> CreateAudioDevice(
unsigned number_of_input_channels,
unsigned number_of_channels,
const WebAudioLatencyHint& latency_hint,
WebAudioDevice::RenderCallback*,
const WebString& device_id) {
return nullptr;
}
// Blob ----------------------------------------------------------------
// Must return non-null.
virtual WebBlobRegistry* GetBlobRegistry() { return nullptr; }
// Database (WebSQL) ---------------------------------------------------
// Opens a database file.
virtual base::File DatabaseOpenFile(const WebString& vfs_file_name,
int desired_flags) {
return base::File();
}
// Deletes a database file and returns the error code.
virtual int DatabaseDeleteFile(const WebString& vfs_file_name,
bool sync_dir) {
return 0;
}
// Returns the attributes of the given database file.
virtual int32_t DatabaseGetFileAttributes(const WebString& vfs_file_name) {
return 0;
}
// Returns the size of the given database file.
virtual int64_t DatabaseGetFileSize(const WebString& vfs_file_name) {
return 0;
}
// Returns the space available for the given origin.
virtual int64_t DatabaseGetSpaceAvailableForOrigin(
const WebSecurityOrigin& origin) {
return 0;
}
// Set the size of the given database file.
virtual bool DatabaseSetFileSize(const WebString& vfs_file_name,
int64_t size) {
return false;
}
// Return a filename-friendly identifier for an origin.
virtual WebString DatabaseCreateOriginIdentifier(
const WebSecurityOrigin& origin) {
return WebString();
}
// DOM Storage --------------------------------------------------
// Return a LocalStorage namespace
virtual std::unique_ptr<WebStorageNamespace> CreateLocalStorageNamespace();
// Return a SessionStorage namespace
virtual std::unique_ptr<WebStorageNamespace> CreateSessionStorageNamespace(
base::StringPiece namespace_id);
// FileSystem ----------------------------------------------------------
// Return a filename-friendly identifier for an origin.
virtual WebString FileSystemCreateOriginIdentifier(
const WebSecurityOrigin& origin) {
return WebString();
}
// IDN conversion ------------------------------------------------------
virtual WebString ConvertIDNToUnicode(const WebString& host) { return host; }
// History -------------------------------------------------------------
// Returns the hash for the given canonicalized URL for use in visited
// link coloring.
virtual uint64_t VisitedLinkHash(const char* canonical_url, size_t length) {
return 0;
}
// Returns whether the given link hash is in the user's history. The
// hash must have been generated by calling VisitedLinkHash().
virtual bool IsLinkVisited(uint64_t link_hash) { return false; }
static const size_t kNoDecodedImageByteLimit = static_cast<size_t>(-1);
// Returns the maximum amount of memory a decoded image should be allowed.
// See comments on ImageDecoder::max_decoded_bytes_.
virtual size_t MaxDecodedImageBytes() { return kNoDecodedImageByteLimit; }
// Returns true if this is a low-end device.
// This is the same as base::SysInfo::IsLowEndDevice.
virtual bool IsLowEndDevice() { return false; }
// Process -------------------------------------------------------------
// Returns a unique FrameSinkID for the current renderer process
virtual viz::FrameSinkId GenerateFrameSinkId() { return viz::FrameSinkId(); }
// Returns whether this process is locked to a single site (i.e. a scheme
// plus eTLD+1, such as https://google.com), or to a more specific origin.
// This means the process will not be used to load documents or workers from
// URLs outside that site.
virtual bool IsLockedToSite() const { return false; }
// Network -------------------------------------------------------------
// Returns the platform's default URLLoaderFactory. It is expected that the
// returned value is stored and to be used for all the CreateURLLoader
// requests for the same loading context.
//
// WARNING: This factory understands http(s) and blob URLs, but it does not
// understand URLs like chrome-extension:// and file:// as those are provided
// by the browser process on a per-frame or per-worker basis. If you require
// support for such URLs, you must add that support manually. Typically you
// get a factory bundle from the browser process, and compose a new factory
// using both the bundle and this default.
//
// TODO(kinuko): https://crbug.com/891872: See if we can deprecate this too.
virtual std::unique_ptr<WebURLLoaderFactory> CreateDefaultURLLoaderFactory() {
return nullptr;
}
// Returns the CodeCacheLoader that is used to fetch data from code caches.
// It is OK to return a nullptr. When a nullptr is returned, data would not
// be fetched from code cache.
virtual std::unique_ptr<CodeCacheLoader> CreateCodeCacheLoader() {
return nullptr;
}
// Returns a new WebURLLoaderFactory that wraps the given
// network::mojom::URLLoaderFactory.
virtual std::unique_ptr<WebURLLoaderFactory> WrapURLLoaderFactory(
mojo::ScopedMessagePipeHandle url_loader_factory_handle) {
return nullptr;
}
// Returns a new WebURLLoaderFactory that wraps the given
// network::SharedURLLoaderFactory.
virtual std::unique_ptr<blink::WebURLLoaderFactory>
WrapSharedURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> factory) {
return nullptr;
}
// May return null.
virtual WebPrescientNetworking* PrescientNetworking() { return nullptr; }
// Returns the User-Agent string.
virtual WebString UserAgent() { return WebString(); }
// Returns the User Agent metadata. This will replace `UserAgent()` if we
// end up shipping https://github.com/WICG/ua-client-hints.
virtual blink::UserAgentMetadata UserAgentMetadata() {
return blink::UserAgentMetadata();
}
// A suggestion to cache this metadata in association with this URL.
virtual void CacheMetadata(blink::mojom::CodeCacheType cache_type,
const WebURL&,
base::Time response_time,
const uint8_t* data,
size_t data_size) {}
// A request to fetch contents associated with this URL from metadata cache.
using FetchCachedCodeCallback =
base::OnceCallback<void(base::Time, base::span<const uint8_t>)>;
virtual void FetchCachedCode(blink::mojom::CodeCacheType cache_type,
const GURL&,
FetchCachedCodeCallback) {}
virtual void ClearCodeCacheEntry(blink::mojom::CodeCacheType cache_type,
const GURL&) {}
// A suggestion to cache this metadata in association with this URL which
// resource is in CacheStorage.
virtual void CacheMetadataInCacheStorage(
const WebURL&,
base::Time response_time,
const uint8_t* data,
size_t data_size,
const blink::WebSecurityOrigin& cache_storage_origin,
const WebString& cache_storage_cache_name) {}
// Public Suffix List --------------------------------------------------
// May return null on some platforms.
virtual WebPublicSuffixList* PublicSuffixList() { return nullptr; }
// Resources -----------------------------------------------------------
// Returns a localized string resource (with substitution parameters).
virtual WebString QueryLocalizedString(WebLocalizedString::Name) {
return WebString();
}
virtual WebString QueryLocalizedString(WebLocalizedString::Name,
const WebString& parameter) {
return WebString();
}
virtual WebString QueryLocalizedString(WebLocalizedString::Name,
const WebString& parameter1,
const WebString& parameter2) {
return WebString();
}
// Threads -------------------------------------------------------
// Most of threading functionality has moved to blink::Thread. The functions
// in Platform are deprecated; use the counterpart in blink::Thread as noted
// below.
// DEPRECATED: Use Thread::CreateThread() instead.
std::unique_ptr<Thread> CreateThread(const ThreadCreationParams&);
// The two compositor-related functions below are called by the embedder.
// TODO(yutak): Perhaps we should move these to somewhere else?
// Create and initialize the compositor thread. After this function
// completes, you can access CompositorThreadTaskRunner().
void CreateAndSetCompositorThread();
// Returns the task runner of the compositor thread. This is available
// once CreateAndSetCompositorThread() is called.
scoped_refptr<base::SingleThreadTaskRunner> CompositorThreadTaskRunner();
// This is called after the compositor thread is created, so the embedder
// can initiate an IPC to change its thread priority (on Linux we can't
// increase the nice value, so we need to ask the browser process). This
// function is only called from the main thread (where InitializeCompositor-
// Thread() is called).
virtual void SetDisplayThreadPriority(base::PlatformThreadId) {}
// Returns a blame context for attributing top-level work which does not
// belong to a particular frame scope.
virtual BlameContext* GetTopLevelBlameContext() { return nullptr; }
// Resources -----------------------------------------------------------
// Returns a blob of data corresponding to the named resource.
virtual WebData GetDataResource(const char* name) { return WebData(); }
// Decodes the in-memory audio file data and returns the linear PCM audio data
// in the |destination_bus|.
// Returns true on success.
virtual bool DecodeAudioFileData(WebAudioBus* destination_bus,
const char* audio_file_data,
size_t data_size) {
return false;
}
// Process lifetime management -----------------------------------------
// Disable/Enable sudden termination on a process level. When possible, it
// is preferable to disable sudden termination on a per-frame level via
// WebLocalFrameClient::SuddenTerminationDisablerChanged.
// This method should only be called on the main thread.
virtual void SuddenTerminationChanged(bool enabled) {}
// System --------------------------------------------------------------
// Returns a value such as "en-US".
virtual WebString DefaultLocale() { return WebString(); }
// Returns an interface to the IO task runner.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() const {
return nullptr;
}
// Returns an interface to run nested message loop. Used for debugging.
class NestedMessageLoopRunner {
public:
virtual ~NestedMessageLoopRunner() = default;
virtual void Run() = 0;
virtual void QuitNow() = 0;
};
virtual std::unique_ptr<NestedMessageLoopRunner>
CreateNestedMessageLoopRunner() const {
return nullptr;
}
// Testing -------------------------------------------------------------
// Gets a pointer to URLLoaderMockFactory for testing. Will not be available
// in production builds.
// TODO(kinuko,toyoshim): Deprecate this one. (crbug.com/751425)
virtual WebURLLoaderMockFactory* GetURLLoaderMockFactory() { return nullptr; }
// Record to a RAPPOR privacy-preserving metric, see:
// https://www.chromium.org/developers/design-documents/rappor.
// RecordRappor records a sample string, while RecordRapporURL records the
// eTLD+1 of a url.
virtual void RecordRappor(const char* metric, const WebString& sample) {}
virtual void RecordRapporURL(const char* metric, const blink::WebURL& url) {}
// Record a UMA sequence action. The UserMetricsAction construction must
// be on a single line for extract_actions.py to find it. Please see
// that script for more details. Intended use is:
// RecordAction(UserMetricsAction("MyAction"))
virtual void RecordAction(const UserMetricsAction&) {}
typedef uint64_t WebMemoryAllocatorDumpGuid;
// GPU ----------------------------------------------------------------
//
enum ContextType {
kWebGL1ContextType, // WebGL 1.0 context, use only for WebGL canvases
kWebGL2ContextType, // WebGL 2.0 context, use only for WebGL canvases
kWebGL2ComputeContextType, // WebGL 2.0 Compute context, use only for WebGL
// canvases
kGLES2ContextType, // GLES 2.0 context, default, good for using skia
kGLES3ContextType, // GLES 3.0 context
kWebGPUContextType, // WebGPU context
};
struct ContextAttributes {
bool prefer_low_power_gpu = false;
bool fail_if_major_performance_caveat = false;
ContextType context_type = kGLES2ContextType;
// Offscreen contexts usually share a surface for the default frame buffer
// since they aren't rendering to it. Setting any of the following
// attributes causes creation of a custom surface owned by the context.
bool support_alpha = false;
bool support_depth = false;
bool support_antialias = false;
bool support_stencil = false;
// Offscreen contexts created for WebGL should not need the RasterInterface
// or GrContext. If either of these are set to false, it will not be
// possible to use the corresponding interface for the lifetime of the
// context.
bool enable_raster_interface = false;
bool support_grcontext = false;
};
struct GraphicsInfo {
unsigned vendor_id = 0;
unsigned device_id = 0;
unsigned reset_notification_strategy = 0;
bool sandboxed = false;
bool amd_switchable = false;
bool optimus = false;
WebString vendor_info;
WebString renderer_info;
WebString driver_version;
WebString error_message;
};
// Returns a newly allocated and initialized offscreen context provider,
// backed by an independent context. Returns null if the context cannot be
// created or initialized.
virtual std::unique_ptr<WebGraphicsContext3DProvider>
CreateOffscreenGraphicsContext3DProvider(
const ContextAttributes&,
const WebURL& top_document_url,
GraphicsInfo*);
// Returns a newly allocated and initialized offscreen context provider,
// backed by the process-wide shared main thread context. Returns null if
// the context cannot be created or initialized.
virtual std::unique_ptr<WebGraphicsContext3DProvider>
CreateSharedOffscreenGraphicsContext3DProvider();
// Returns a newly allocated and initialized WebGPU context provider,
// backed by an independent context. Returns null if the context cannot be
// created or initialized.
virtual std::unique_ptr<WebGraphicsContext3DProvider>
CreateWebGPUGraphicsContext3DProvider(const WebURL& top_document_url,
GraphicsInfo*);
virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() {
return nullptr;
}
// When true, animations will run on a compositor thread independently from
// the blink main thread.
// This is true when there exists a renderer compositor in this process. But
// for unit tests, a single-threaded compositor may be used so it may remain
// false.
virtual bool IsThreadedAnimationEnabled() { return false; }
// Whether the compositor is using gpu and expects gpu resources as inputs,
// or software based resources.
// NOTE: This function should not be called from core/ and modules/, but
// called by platform/graphics/ is fine.
virtual bool IsGpuCompositingDisabled() { return true; }
// WebRTC ----------------------------------------------------------
// Creates a WebRTCPeerConnectionHandler for RTCPeerConnection.
// May return null if WebRTC functionality is not avaliable or if it's out of
// resources.
virtual std::unique_ptr<WebRTCPeerConnectionHandler>
CreateRTCPeerConnectionHandler(WebRTCPeerConnectionHandlerClient*,
scoped_refptr<base::SingleThreadTaskRunner>);
// Creates a WebMediaRecorderHandler to record MediaStreams.
// May return null if the functionality is not available or out of resources.
virtual std::unique_ptr<WebMediaRecorderHandler> CreateMediaRecorderHandler(
scoped_refptr<base::SingleThreadTaskRunner>);
// May return null if WebRTC functionality is not available or out of
// resources.
virtual std::unique_ptr<WebRTCCertificateGenerator>
CreateRTCCertificateGenerator();
// May return null if WebRTC functionality is not available or out of
// resources.
virtual std::unique_ptr<WebMediaStreamCenter> CreateMediaStreamCenter();
// Returns the SingleThreadTaskRunner suitable for running WebRTC networking.
// An rtc::Thread will have already been created.
// May return null if WebRTC functionality is not implemented.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetWebRtcWorkerThread() {
return nullptr;
}
// Returns the rtc::Thread instance associated with the WebRTC worker thread.
// TODO(bugs.webrtc.org/9419): Remove once WebRTC can be built as a component.
// May return null if WebRTC functionality is not implemented.
virtual rtc::Thread* GetWebRtcWorkerThreadRtcThread() { return nullptr; }
// May return null if WebRTC functionality is not implemented.
virtual std::unique_ptr<cricket::PortAllocator> CreateWebRtcPortAllocator(
WebLocalFrame* frame);
// May return null if WebRTC functionality is not implemented.
virtual std::unique_ptr<webrtc::AsyncResolverFactory>
CreateWebRtcAsyncResolverFactory();
// Fills in the WebMediaStream to capture from the WebMediaPlayer identified
// by the second parameter.
virtual void CreateHTMLAudioElementCapturer(
WebMediaStream*,
WebMediaPlayer*,
scoped_refptr<base::SingleThreadTaskRunner>) {}
// Returns the most optimistic view of the capabilities of the system for
// sending or receiving media of the given kind ("audio" or "video").
virtual std::unique_ptr<webrtc::RtpCapabilities> GetRtpSenderCapabilities(
const WebString& kind);
virtual std::unique_ptr<webrtc::RtpCapabilities> GetRtpReceiverCapabilities(
const WebString& kind);
virtual void UpdateWebRTCAPICount(WebRTCAPIName api_name) {}
virtual base::Optional<double> GetWebRtcMaxCaptureFrameRate() {
return base::nullopt;
}
// WebWorker ----------------------------------------------------------
virtual std::unique_ptr<WebDedicatedWorkerHostFactoryClient>
CreateDedicatedWorkerHostFactoryClient(WebDedicatedWorker*,
service_manager::InterfaceProvider*) {
return nullptr;
}
virtual void DidStartWorkerThread() {}
virtual void WillStopWorkerThread() {}
virtual void WorkerContextCreated(const v8::Local<v8::Context>& worker) {}
virtual bool AllowScriptExtensionForServiceWorker(
const WebSecurityOrigin& script_origin) {
return false;
}
virtual bool IsExcludedHeaderForServiceWorkerFetchEvent(
const WebString& header_name) {
return false;
}
// WebCrypto ----------------------------------------------------------
virtual WebCrypto* Crypto() { return nullptr; }
// Mojo ---------------------------------------------------------------
virtual service_manager::Connector* GetConnector();
virtual InterfaceProvider* GetInterfaceProvider();
virtual const char* GetBrowserServiceName() const { return ""; }
// WebDatabase --------------------------------------------------------
virtual WebDatabaseObserver* DatabaseObserver() { return nullptr; }
// Media Capabilities --------------------------------------------------
virtual WebMediaCapabilitiesClient* MediaCapabilitiesClient() {
return nullptr;
}
virtual WebTransmissionEncodingInfoHandler*
TransmissionEncodingInfoHandler() {
return nullptr;
}
// Renderer Memory Metrics ----------------------------------------------
virtual void RecordMetricsForBackgroundedRendererPurge() {}
// V8 Context Snapshot --------------------------------------------------
// This method returns true only when
// tools/v8_context_snapshot/v8_context_snapshot_generator is running (which
// runs during Chromium's build step).
virtual bool IsTakingV8ContextSnapshot() { return false; }
private:
static void InitializeCommon(Platform* platform,
std::unique_ptr<Thread> main_thread);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_PLATFORM_H_
| [
"sunny.nam@samsung.com"
] | sunny.nam@samsung.com |
3aedf278451a2ed9a4e698b925414083dee70e41 | 593be54119db4bbd129daa33dd967e1d7dbd3a37 | /midterm2/src/factory.h | c6b63acb70a70cd67e4d5aa4b8951e6d17ce8ac8 | [] | no_license | ChuGP/POSD | f72ee56fba181dbd84b03d0ac42abc96e3882cf9 | 6b53d260b50b652eb495049fd41be734602c37bc | refs/heads/master | 2020-04-24T02:28:18.123404 | 2020-02-10T03:58:16 | 2020-02-10T03:58:16 | 171,637,703 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 208 | h | #ifndef FACTORY_H
#define FACTORY_H
#include "shape.h"
class Factory
{
public:
Factory()
{
} // triangle
virtual Shape * create() {}; // 繼承他的自行決定實作
};
#endif | [
"a5824384@gmail.com"
] | a5824384@gmail.com |
9cb7923c2d611eb80c2ef3978f9311c291747700 | dd8849cba469e624c4152dbf85a735acabdf3fd3 | /test/normalize_to_nfc_050.cpp | 5da9e3ae643cafb667b318bcb723438d6a12eac7 | [
"LicenseRef-scancode-unknown-license-reference",
"BSL-1.0"
] | permissive | skyformat99/text | e237dce1cced4b8b92a1d80d4b25c99edb5772d6 | f9e5979710c9a391e81f3f432ea6fd04e97d5490 | refs/heads/master | 2020-03-22T04:35:53.875892 | 2018-07-01T13:21:27 | 2018-07-01T13:21:27 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 732,547 | cpp | // Warning! This file is autogenerated.
#include <boost/text/normalize_string.hpp>
#include <boost/text/utility.hpp>
#include <gtest/gtest.h>
#include <algorithm>
TEST(normalization, nfc_050_000)
{
// C9A0;C9A0;110C 1173 11BF;C9A0;110C 1173 11BF;
// (즠; 즠; 즠; 즠; 즠; ) HANGUL SYLLABLE JEUK
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A0 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1173, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A0 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1173, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_001)
{
// C9A1;C9A1;110C 1173 11C0;C9A1;110C 1173 11C0;
// (즡; 즡; 즡; 즡; 즡; ) HANGUL SYLLABLE JEUT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1173, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1173, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_002)
{
// C9A2;C9A2;110C 1173 11C1;C9A2;110C 1173 11C1;
// (즢; 즢; 즢; 즢; 즢; ) HANGUL SYLLABLE JEUP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1173, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1173, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_003)
{
// C9A3;C9A3;110C 1173 11C2;C9A3;110C 1173 11C2;
// (즣; 즣; 즣; 즣; 즣; ) HANGUL SYLLABLE JEUH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1173, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1173, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_004)
{
// C9A4;C9A4;110C 1174;C9A4;110C 1174;
// (즤; 즤; 즤; 즤; 즤; ) HANGUL SYLLABLE JYI
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A4 }};
std::array<uint32_t, 2> const c3 = {{ 0x110C, 0x1174 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A4 }};
std::array<uint32_t, 2> const c5 = {{ 0x110C, 0x1174 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_005)
{
// C9A5;C9A5;110C 1174 11A8;C9A5;110C 1174 11A8;
// (즥; 즥; 즥; 즥; 즥; ) HANGUL SYLLABLE JYIG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_006)
{
// C9A6;C9A6;110C 1174 11A9;C9A6;110C 1174 11A9;
// (즦; 즦; 즦; 즦; 즦; ) HANGUL SYLLABLE JYIGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_007)
{
// C9A7;C9A7;110C 1174 11AA;C9A7;110C 1174 11AA;
// (즧; 즧; 즧; 즧; 즧; ) HANGUL SYLLABLE JYIGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_008)
{
// C9A8;C9A8;110C 1174 11AB;C9A8;110C 1174 11AB;
// (즨; 즨; 즨; 즨; 즨; ) HANGUL SYLLABLE JYIN
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A8 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A8 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_009)
{
// C9A9;C9A9;110C 1174 11AC;C9A9;110C 1174 11AC;
// (즩; 즩; 즩; 즩; 즩; ) HANGUL SYLLABLE JYINJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9A9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9A9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9A9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_010)
{
// C9AA;C9AA;110C 1174 11AD;C9AA;110C 1174 11AD;
// (즪; 즪; 즪; 즪; 즪; ) HANGUL SYLLABLE JYINH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AA }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AA }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_011)
{
// C9AB;C9AB;110C 1174 11AE;C9AB;110C 1174 11AE;
// (즫; 즫; 즫; 즫; 즫; ) HANGUL SYLLABLE JYID
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AB }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AB }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_012)
{
// C9AC;C9AC;110C 1174 11AF;C9AC;110C 1174 11AF;
// (즬; 즬; 즬; 즬; 즬; ) HANGUL SYLLABLE JYIL
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AC }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AC }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_013)
{
// C9AD;C9AD;110C 1174 11B0;C9AD;110C 1174 11B0;
// (즭; 즭; 즭; 즭; 즭; ) HANGUL SYLLABLE JYILG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AD }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AD }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AD }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_014)
{
// C9AE;C9AE;110C 1174 11B1;C9AE;110C 1174 11B1;
// (즮; 즮; 즮; 즮; 즮; ) HANGUL SYLLABLE JYILM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AE }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AE }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_015)
{
// C9AF;C9AF;110C 1174 11B2;C9AF;110C 1174 11B2;
// (즯; 즯; 즯; 즯; 즯; ) HANGUL SYLLABLE JYILB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9AF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9AF }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9AF }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_016)
{
// C9B0;C9B0;110C 1174 11B3;C9B0;110C 1174 11B3;
// (즰; 즰; 즰; 즰; 즰; ) HANGUL SYLLABLE JYILS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B0 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B0 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_017)
{
// C9B1;C9B1;110C 1174 11B4;C9B1;110C 1174 11B4;
// (즱; 즱; 즱; 즱; 즱; ) HANGUL SYLLABLE JYILT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_018)
{
// C9B2;C9B2;110C 1174 11B5;C9B2;110C 1174 11B5;
// (즲; 즲; 즲; 즲; 즲; ) HANGUL SYLLABLE JYILP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_019)
{
// C9B3;C9B3;110C 1174 11B6;C9B3;110C 1174 11B6;
// (즳; 즳; 즳; 즳; 즳; ) HANGUL SYLLABLE JYILH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_020)
{
// C9B4;C9B4;110C 1174 11B7;C9B4;110C 1174 11B7;
// (즴; 즴; 즴; 즴; 즴; ) HANGUL SYLLABLE JYIM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B4 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B4 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_021)
{
// C9B5;C9B5;110C 1174 11B8;C9B5;110C 1174 11B8;
// (즵; 즵; 즵; 즵; 즵; ) HANGUL SYLLABLE JYIB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_022)
{
// C9B6;C9B6;110C 1174 11B9;C9B6;110C 1174 11B9;
// (즶; 즶; 즶; 즶; 즶; ) HANGUL SYLLABLE JYIBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_023)
{
// C9B7;C9B7;110C 1174 11BA;C9B7;110C 1174 11BA;
// (즷; 즷; 즷; 즷; 즷; ) HANGUL SYLLABLE JYIS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_024)
{
// C9B8;C9B8;110C 1174 11BB;C9B8;110C 1174 11BB;
// (즸; 즸; 즸; 즸; 즸; ) HANGUL SYLLABLE JYISS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B8 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B8 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_025)
{
// C9B9;C9B9;110C 1174 11BC;C9B9;110C 1174 11BC;
// (즹; 즹; 즹; 즹; 즹; ) HANGUL SYLLABLE JYING
{
std::array<uint32_t, 1> const c1 = {{ 0xC9B9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9B9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9B9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_026)
{
// C9BA;C9BA;110C 1174 11BD;C9BA;110C 1174 11BD;
// (즺; 즺; 즺; 즺; 즺; ) HANGUL SYLLABLE JYIJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BA }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BA }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_027)
{
// C9BB;C9BB;110C 1174 11BE;C9BB;110C 1174 11BE;
// (즻; 즻; 즻; 즻; 즻; ) HANGUL SYLLABLE JYIC
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BB }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BB }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_028)
{
// C9BC;C9BC;110C 1174 11BF;C9BC;110C 1174 11BF;
// (즼; 즼; 즼; 즼; 즼; ) HANGUL SYLLABLE JYIK
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BC }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BC }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_029)
{
// C9BD;C9BD;110C 1174 11C0;C9BD;110C 1174 11C0;
// (즽; 즽; 즽; 즽; 즽; ) HANGUL SYLLABLE JYIT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BD }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BD }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BD }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_030)
{
// C9BE;C9BE;110C 1174 11C1;C9BE;110C 1174 11C1;
// (즾; 즾; 즾; 즾; 즾; ) HANGUL SYLLABLE JYIP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BE }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BE }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_031)
{
// C9BF;C9BF;110C 1174 11C2;C9BF;110C 1174 11C2;
// (즿; 즿; 즿; 즿; 즿; ) HANGUL SYLLABLE JYIH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9BF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9BF }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1174, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9BF }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1174, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_032)
{
// C9C0;C9C0;110C 1175;C9C0;110C 1175;
// (지; 지; 지; 지; 지; ) HANGUL SYLLABLE JI
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C0 }};
std::array<uint32_t, 2> const c3 = {{ 0x110C, 0x1175 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C0 }};
std::array<uint32_t, 2> const c5 = {{ 0x110C, 0x1175 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_033)
{
// C9C1;C9C1;110C 1175 11A8;C9C1;110C 1175 11A8;
// (직; 직; 직; 직; 직; ) HANGUL SYLLABLE JIG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_034)
{
// C9C2;C9C2;110C 1175 11A9;C9C2;110C 1175 11A9;
// (짂; 짂; 짂; 짂; 짂; ) HANGUL SYLLABLE JIGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_035)
{
// C9C3;C9C3;110C 1175 11AA;C9C3;110C 1175 11AA;
// (짃; 짃; 짃; 짃; 짃; ) HANGUL SYLLABLE JIGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_036)
{
// C9C4;C9C4;110C 1175 11AB;C9C4;110C 1175 11AB;
// (진; 진; 진; 진; 진; ) HANGUL SYLLABLE JIN
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C4 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C4 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_037)
{
// C9C5;C9C5;110C 1175 11AC;C9C5;110C 1175 11AC;
// (짅; 짅; 짅; 짅; 짅; ) HANGUL SYLLABLE JINJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_038)
{
// C9C6;C9C6;110C 1175 11AD;C9C6;110C 1175 11AD;
// (짆; 짆; 짆; 짆; 짆; ) HANGUL SYLLABLE JINH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_039)
{
// C9C7;C9C7;110C 1175 11AE;C9C7;110C 1175 11AE;
// (짇; 짇; 짇; 짇; 짇; ) HANGUL SYLLABLE JID
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_040)
{
// C9C8;C9C8;110C 1175 11AF;C9C8;110C 1175 11AF;
// (질; 질; 질; 질; 질; ) HANGUL SYLLABLE JIL
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C8 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C8 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_041)
{
// C9C9;C9C9;110C 1175 11B0;C9C9;110C 1175 11B0;
// (짉; 짉; 짉; 짉; 짉; ) HANGUL SYLLABLE JILG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9C9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9C9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9C9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_042)
{
// C9CA;C9CA;110C 1175 11B1;C9CA;110C 1175 11B1;
// (짊; 짊; 짊; 짊; 짊; ) HANGUL SYLLABLE JILM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CA }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CA }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_043)
{
// C9CB;C9CB;110C 1175 11B2;C9CB;110C 1175 11B2;
// (짋; 짋; 짋; 짋; 짋; ) HANGUL SYLLABLE JILB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CB }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CB }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_044)
{
// C9CC;C9CC;110C 1175 11B3;C9CC;110C 1175 11B3;
// (짌; 짌; 짌; 짌; 짌; ) HANGUL SYLLABLE JILS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CC }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CC }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_045)
{
// C9CD;C9CD;110C 1175 11B4;C9CD;110C 1175 11B4;
// (짍; 짍; 짍; 짍; 짍; ) HANGUL SYLLABLE JILT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CD }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CD }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CD }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_046)
{
// C9CE;C9CE;110C 1175 11B5;C9CE;110C 1175 11B5;
// (짎; 짎; 짎; 짎; 짎; ) HANGUL SYLLABLE JILP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CE }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CE }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_047)
{
// C9CF;C9CF;110C 1175 11B6;C9CF;110C 1175 11B6;
// (짏; 짏; 짏; 짏; 짏; ) HANGUL SYLLABLE JILH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9CF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9CF }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9CF }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_048)
{
// C9D0;C9D0;110C 1175 11B7;C9D0;110C 1175 11B7;
// (짐; 짐; 짐; 짐; 짐; ) HANGUL SYLLABLE JIM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D0 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D0 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_049)
{
// C9D1;C9D1;110C 1175 11B8;C9D1;110C 1175 11B8;
// (집; 집; 집; 집; 집; ) HANGUL SYLLABLE JIB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_050)
{
// C9D2;C9D2;110C 1175 11B9;C9D2;110C 1175 11B9;
// (짒; 짒; 짒; 짒; 짒; ) HANGUL SYLLABLE JIBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_051)
{
// C9D3;C9D3;110C 1175 11BA;C9D3;110C 1175 11BA;
// (짓; 짓; 짓; 짓; 짓; ) HANGUL SYLLABLE JIS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_052)
{
// C9D4;C9D4;110C 1175 11BB;C9D4;110C 1175 11BB;
// (짔; 짔; 짔; 짔; 짔; ) HANGUL SYLLABLE JISS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D4 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D4 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_053)
{
// C9D5;C9D5;110C 1175 11BC;C9D5;110C 1175 11BC;
// (징; 징; 징; 징; 징; ) HANGUL SYLLABLE JING
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_054)
{
// C9D6;C9D6;110C 1175 11BD;C9D6;110C 1175 11BD;
// (짖; 짖; 짖; 짖; 짖; ) HANGUL SYLLABLE JIJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_055)
{
// C9D7;C9D7;110C 1175 11BE;C9D7;110C 1175 11BE;
// (짗; 짗; 짗; 짗; 짗; ) HANGUL SYLLABLE JIC
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_056)
{
// C9D8;C9D8;110C 1175 11BF;C9D8;110C 1175 11BF;
// (짘; 짘; 짘; 짘; 짘; ) HANGUL SYLLABLE JIK
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D8 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D8 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_057)
{
// C9D9;C9D9;110C 1175 11C0;C9D9;110C 1175 11C0;
// (짙; 짙; 짙; 짙; 짙; ) HANGUL SYLLABLE JIT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9D9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9D9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9D9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_058)
{
// C9DA;C9DA;110C 1175 11C1;C9DA;110C 1175 11C1;
// (짚; 짚; 짚; 짚; 짚; ) HANGUL SYLLABLE JIP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DA }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DA }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_059)
{
// C9DB;C9DB;110C 1175 11C2;C9DB;110C 1175 11C2;
// (짛; 짛; 짛; 짛; 짛; ) HANGUL SYLLABLE JIH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DB }};
std::array<uint32_t, 3> const c3 = {{ 0x110C, 0x1175, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DB }};
std::array<uint32_t, 3> const c5 = {{ 0x110C, 0x1175, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_060)
{
// C9DC;C9DC;110D 1161;C9DC;110D 1161;
// (짜; 짜; 짜; 짜; 짜; ) HANGUL SYLLABLE JJA
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DC }};
std::array<uint32_t, 2> const c3 = {{ 0x110D, 0x1161 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DC }};
std::array<uint32_t, 2> const c5 = {{ 0x110D, 0x1161 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_061)
{
// C9DD;C9DD;110D 1161 11A8;C9DD;110D 1161 11A8;
// (짝; 짝; 짝; 짝; 짝; ) HANGUL SYLLABLE JJAG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DD }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DD }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DD }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_062)
{
// C9DE;C9DE;110D 1161 11A9;C9DE;110D 1161 11A9;
// (짞; 짞; 짞; 짞; 짞; ) HANGUL SYLLABLE JJAGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DE }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DE }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_063)
{
// C9DF;C9DF;110D 1161 11AA;C9DF;110D 1161 11AA;
// (짟; 짟; 짟; 짟; 짟; ) HANGUL SYLLABLE JJAGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9DF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9DF }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9DF }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_064)
{
// C9E0;C9E0;110D 1161 11AB;C9E0;110D 1161 11AB;
// (짠; 짠; 짠; 짠; 짠; ) HANGUL SYLLABLE JJAN
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E0 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E0 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_065)
{
// C9E1;C9E1;110D 1161 11AC;C9E1;110D 1161 11AC;
// (짡; 짡; 짡; 짡; 짡; ) HANGUL SYLLABLE JJANJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_066)
{
// C9E2;C9E2;110D 1161 11AD;C9E2;110D 1161 11AD;
// (짢; 짢; 짢; 짢; 짢; ) HANGUL SYLLABLE JJANH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_067)
{
// C9E3;C9E3;110D 1161 11AE;C9E3;110D 1161 11AE;
// (짣; 짣; 짣; 짣; 짣; ) HANGUL SYLLABLE JJAD
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_068)
{
// C9E4;C9E4;110D 1161 11AF;C9E4;110D 1161 11AF;
// (짤; 짤; 짤; 짤; 짤; ) HANGUL SYLLABLE JJAL
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E4 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E4 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_069)
{
// C9E5;C9E5;110D 1161 11B0;C9E5;110D 1161 11B0;
// (짥; 짥; 짥; 짥; 짥; ) HANGUL SYLLABLE JJALG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_070)
{
// C9E6;C9E6;110D 1161 11B1;C9E6;110D 1161 11B1;
// (짦; 짦; 짦; 짦; 짦; ) HANGUL SYLLABLE JJALM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_071)
{
// C9E7;C9E7;110D 1161 11B2;C9E7;110D 1161 11B2;
// (짧; 짧; 짧; 짧; 짧; ) HANGUL SYLLABLE JJALB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_072)
{
// C9E8;C9E8;110D 1161 11B3;C9E8;110D 1161 11B3;
// (짨; 짨; 짨; 짨; 짨; ) HANGUL SYLLABLE JJALS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E8 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E8 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_073)
{
// C9E9;C9E9;110D 1161 11B4;C9E9;110D 1161 11B4;
// (짩; 짩; 짩; 짩; 짩; ) HANGUL SYLLABLE JJALT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9E9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9E9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9E9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_074)
{
// C9EA;C9EA;110D 1161 11B5;C9EA;110D 1161 11B5;
// (짪; 짪; 짪; 짪; 짪; ) HANGUL SYLLABLE JJALP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9EA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9EA }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9EA }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_075)
{
// C9EB;C9EB;110D 1161 11B6;C9EB;110D 1161 11B6;
// (짫; 짫; 짫; 짫; 짫; ) HANGUL SYLLABLE JJALH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9EB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9EB }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9EB }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_076)
{
// C9EC;C9EC;110D 1161 11B7;C9EC;110D 1161 11B7;
// (짬; 짬; 짬; 짬; 짬; ) HANGUL SYLLABLE JJAM
{
std::array<uint32_t, 1> const c1 = {{ 0xC9EC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9EC }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9EC }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_077)
{
// C9ED;C9ED;110D 1161 11B8;C9ED;110D 1161 11B8;
// (짭; 짭; 짭; 짭; 짭; ) HANGUL SYLLABLE JJAB
{
std::array<uint32_t, 1> const c1 = {{ 0xC9ED }};
std::array<uint32_t, 1> const c2 = {{ 0xC9ED }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9ED }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_078)
{
// C9EE;C9EE;110D 1161 11B9;C9EE;110D 1161 11B9;
// (짮; 짮; 짮; 짮; 짮; ) HANGUL SYLLABLE JJABS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9EE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9EE }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9EE }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_079)
{
// C9EF;C9EF;110D 1161 11BA;C9EF;110D 1161 11BA;
// (짯; 짯; 짯; 짯; 짯; ) HANGUL SYLLABLE JJAS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9EF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9EF }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9EF }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_080)
{
// C9F0;C9F0;110D 1161 11BB;C9F0;110D 1161 11BB;
// (짰; 짰; 짰; 짰; 짰; ) HANGUL SYLLABLE JJASS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F0 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F0 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_081)
{
// C9F1;C9F1;110D 1161 11BC;C9F1;110D 1161 11BC;
// (짱; 짱; 짱; 짱; 짱; ) HANGUL SYLLABLE JJANG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F1 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F1 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_082)
{
// C9F2;C9F2;110D 1161 11BD;C9F2;110D 1161 11BD;
// (짲; 짲; 짲; 짲; 짲; ) HANGUL SYLLABLE JJAJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F2 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F2 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_083)
{
// C9F3;C9F3;110D 1161 11BE;C9F3;110D 1161 11BE;
// (짳; 짳; 짳; 짳; 짳; ) HANGUL SYLLABLE JJAC
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F3 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F3 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_084)
{
// C9F4;C9F4;110D 1161 11BF;C9F4;110D 1161 11BF;
// (짴; 짴; 짴; 짴; 짴; ) HANGUL SYLLABLE JJAK
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F4 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F4 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_085)
{
// C9F5;C9F5;110D 1161 11C0;C9F5;110D 1161 11C0;
// (짵; 짵; 짵; 짵; 짵; ) HANGUL SYLLABLE JJAT
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F5 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F5 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_086)
{
// C9F6;C9F6;110D 1161 11C1;C9F6;110D 1161 11C1;
// (짶; 짶; 짶; 짶; 짶; ) HANGUL SYLLABLE JJAP
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F6 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F6 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_087)
{
// C9F7;C9F7;110D 1161 11C2;C9F7;110D 1161 11C2;
// (짷; 짷; 짷; 짷; 짷; ) HANGUL SYLLABLE JJAH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F7 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1161, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F7 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1161, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_088)
{
// C9F8;C9F8;110D 1162;C9F8;110D 1162;
// (째; 째; 째; 째; 째; ) HANGUL SYLLABLE JJAE
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F8 }};
std::array<uint32_t, 2> const c3 = {{ 0x110D, 0x1162 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F8 }};
std::array<uint32_t, 2> const c5 = {{ 0x110D, 0x1162 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_089)
{
// C9F9;C9F9;110D 1162 11A8;C9F9;110D 1162 11A8;
// (짹; 짹; 짹; 짹; 짹; ) HANGUL SYLLABLE JJAEG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9F9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC9F9 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9F9 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_090)
{
// C9FA;C9FA;110D 1162 11A9;C9FA;110D 1162 11A9;
// (짺; 짺; 짺; 짺; 짺; ) HANGUL SYLLABLE JJAEGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FA }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FA }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FA }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_091)
{
// C9FB;C9FB;110D 1162 11AA;C9FB;110D 1162 11AA;
// (짻; 짻; 짻; 짻; 짻; ) HANGUL SYLLABLE JJAEGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FB }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FB }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FB }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_092)
{
// C9FC;C9FC;110D 1162 11AB;C9FC;110D 1162 11AB;
// (짼; 짼; 짼; 짼; 짼; ) HANGUL SYLLABLE JJAEN
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FC }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FC }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FC }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_093)
{
// C9FD;C9FD;110D 1162 11AC;C9FD;110D 1162 11AC;
// (짽; 짽; 짽; 짽; 짽; ) HANGUL SYLLABLE JJAENJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FD }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FD }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FD }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_094)
{
// C9FE;C9FE;110D 1162 11AD;C9FE;110D 1162 11AD;
// (짾; 짾; 짾; 짾; 짾; ) HANGUL SYLLABLE JJAENH
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FE }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FE }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FE }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_095)
{
// C9FF;C9FF;110D 1162 11AE;C9FF;110D 1162 11AE;
// (짿; 짿; 짿; 짿; 짿; ) HANGUL SYLLABLE JJAED
{
std::array<uint32_t, 1> const c1 = {{ 0xC9FF }};
std::array<uint32_t, 1> const c2 = {{ 0xC9FF }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC9FF }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_096)
{
// CA00;CA00;110D 1162 11AF;CA00;110D 1162 11AF;
// (쨀; 쨀; 쨀; 쨀; 쨀; ) HANGUL SYLLABLE JJAEL
{
std::array<uint32_t, 1> const c1 = {{ 0xCA00 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA00 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA00 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_097)
{
// CA01;CA01;110D 1162 11B0;CA01;110D 1162 11B0;
// (쨁; 쨁; 쨁; 쨁; 쨁; ) HANGUL SYLLABLE JJAELG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA01 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA01 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA01 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_098)
{
// CA02;CA02;110D 1162 11B1;CA02;110D 1162 11B1;
// (쨂; 쨂; 쨂; 쨂; 쨂; ) HANGUL SYLLABLE JJAELM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA02 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA02 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA02 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_099)
{
// CA03;CA03;110D 1162 11B2;CA03;110D 1162 11B2;
// (쨃; 쨃; 쨃; 쨃; 쨃; ) HANGUL SYLLABLE JJAELB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA03 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA03 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA03 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_100)
{
// CA04;CA04;110D 1162 11B3;CA04;110D 1162 11B3;
// (쨄; 쨄; 쨄; 쨄; 쨄; ) HANGUL SYLLABLE JJAELS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA04 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA04 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA04 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_101)
{
// CA05;CA05;110D 1162 11B4;CA05;110D 1162 11B4;
// (쨅; 쨅; 쨅; 쨅; 쨅; ) HANGUL SYLLABLE JJAELT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA05 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA05 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA05 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_102)
{
// CA06;CA06;110D 1162 11B5;CA06;110D 1162 11B5;
// (쨆; 쨆; 쨆; 쨆; 쨆; ) HANGUL SYLLABLE JJAELP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA06 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA06 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA06 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_103)
{
// CA07;CA07;110D 1162 11B6;CA07;110D 1162 11B6;
// (쨇; 쨇; 쨇; 쨇; 쨇; ) HANGUL SYLLABLE JJAELH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA07 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA07 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA07 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_104)
{
// CA08;CA08;110D 1162 11B7;CA08;110D 1162 11B7;
// (쨈; 쨈; 쨈; 쨈; 쨈; ) HANGUL SYLLABLE JJAEM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA08 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA08 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA08 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_105)
{
// CA09;CA09;110D 1162 11B8;CA09;110D 1162 11B8;
// (쨉; 쨉; 쨉; 쨉; 쨉; ) HANGUL SYLLABLE JJAEB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA09 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA09 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA09 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_106)
{
// CA0A;CA0A;110D 1162 11B9;CA0A;110D 1162 11B9;
// (쨊; 쨊; 쨊; 쨊; 쨊; ) HANGUL SYLLABLE JJAEBS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_107)
{
// CA0B;CA0B;110D 1162 11BA;CA0B;110D 1162 11BA;
// (쨋; 쨋; 쨋; 쨋; 쨋; ) HANGUL SYLLABLE JJAES
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_108)
{
// CA0C;CA0C;110D 1162 11BB;CA0C;110D 1162 11BB;
// (쨌; 쨌; 쨌; 쨌; 쨌; ) HANGUL SYLLABLE JJAESS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0C }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0C }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_109)
{
// CA0D;CA0D;110D 1162 11BC;CA0D;110D 1162 11BC;
// (쨍; 쨍; 쨍; 쨍; 쨍; ) HANGUL SYLLABLE JJAENG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_110)
{
// CA0E;CA0E;110D 1162 11BD;CA0E;110D 1162 11BD;
// (쨎; 쨎; 쨎; 쨎; 쨎; ) HANGUL SYLLABLE JJAEJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_111)
{
// CA0F;CA0F;110D 1162 11BE;CA0F;110D 1162 11BE;
// (쨏; 쨏; 쨏; 쨏; 쨏; ) HANGUL SYLLABLE JJAEC
{
std::array<uint32_t, 1> const c1 = {{ 0xCA0F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA0F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA0F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_112)
{
// CA10;CA10;110D 1162 11BF;CA10;110D 1162 11BF;
// (쨐; 쨐; 쨐; 쨐; 쨐; ) HANGUL SYLLABLE JJAEK
{
std::array<uint32_t, 1> const c1 = {{ 0xCA10 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA10 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA10 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_113)
{
// CA11;CA11;110D 1162 11C0;CA11;110D 1162 11C0;
// (쨑; 쨑; 쨑; 쨑; 쨑; ) HANGUL SYLLABLE JJAET
{
std::array<uint32_t, 1> const c1 = {{ 0xCA11 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA11 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA11 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_114)
{
// CA12;CA12;110D 1162 11C1;CA12;110D 1162 11C1;
// (쨒; 쨒; 쨒; 쨒; 쨒; ) HANGUL SYLLABLE JJAEP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA12 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA12 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA12 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_115)
{
// CA13;CA13;110D 1162 11C2;CA13;110D 1162 11C2;
// (쨓; 쨓; 쨓; 쨓; 쨓; ) HANGUL SYLLABLE JJAEH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA13 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA13 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1162, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA13 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1162, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_116)
{
// CA14;CA14;110D 1163;CA14;110D 1163;
// (쨔; 쨔; 쨔; 쨔; 쨔; ) HANGUL SYLLABLE JJYA
{
std::array<uint32_t, 1> const c1 = {{ 0xCA14 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA14 }};
std::array<uint32_t, 2> const c3 = {{ 0x110D, 0x1163 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA14 }};
std::array<uint32_t, 2> const c5 = {{ 0x110D, 0x1163 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_117)
{
// CA15;CA15;110D 1163 11A8;CA15;110D 1163 11A8;
// (쨕; 쨕; 쨕; 쨕; 쨕; ) HANGUL SYLLABLE JJYAG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA15 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA15 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA15 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_118)
{
// CA16;CA16;110D 1163 11A9;CA16;110D 1163 11A9;
// (쨖; 쨖; 쨖; 쨖; 쨖; ) HANGUL SYLLABLE JJYAGG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA16 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA16 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA16 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_119)
{
// CA17;CA17;110D 1163 11AA;CA17;110D 1163 11AA;
// (쨗; 쨗; 쨗; 쨗; 쨗; ) HANGUL SYLLABLE JJYAGS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA17 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA17 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA17 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_120)
{
// CA18;CA18;110D 1163 11AB;CA18;110D 1163 11AB;
// (쨘; 쨘; 쨘; 쨘; 쨘; ) HANGUL SYLLABLE JJYAN
{
std::array<uint32_t, 1> const c1 = {{ 0xCA18 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA18 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA18 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_121)
{
// CA19;CA19;110D 1163 11AC;CA19;110D 1163 11AC;
// (쨙; 쨙; 쨙; 쨙; 쨙; ) HANGUL SYLLABLE JJYANJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA19 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA19 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA19 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_122)
{
// CA1A;CA1A;110D 1163 11AD;CA1A;110D 1163 11AD;
// (쨚; 쨚; 쨚; 쨚; 쨚; ) HANGUL SYLLABLE JJYANH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_123)
{
// CA1B;CA1B;110D 1163 11AE;CA1B;110D 1163 11AE;
// (쨛; 쨛; 쨛; 쨛; 쨛; ) HANGUL SYLLABLE JJYAD
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_124)
{
// CA1C;CA1C;110D 1163 11AF;CA1C;110D 1163 11AF;
// (쨜; 쨜; 쨜; 쨜; 쨜; ) HANGUL SYLLABLE JJYAL
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1C }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1C }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_125)
{
// CA1D;CA1D;110D 1163 11B0;CA1D;110D 1163 11B0;
// (쨝; 쨝; 쨝; 쨝; 쨝; ) HANGUL SYLLABLE JJYALG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_126)
{
// CA1E;CA1E;110D 1163 11B1;CA1E;110D 1163 11B1;
// (쨞; 쨞; 쨞; 쨞; 쨞; ) HANGUL SYLLABLE JJYALM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_127)
{
// CA1F;CA1F;110D 1163 11B2;CA1F;110D 1163 11B2;
// (쨟; 쨟; 쨟; 쨟; 쨟; ) HANGUL SYLLABLE JJYALB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA1F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA1F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA1F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_128)
{
// CA20;CA20;110D 1163 11B3;CA20;110D 1163 11B3;
// (쨠; 쨠; 쨠; 쨠; 쨠; ) HANGUL SYLLABLE JJYALS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA20 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA20 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA20 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_129)
{
// CA21;CA21;110D 1163 11B4;CA21;110D 1163 11B4;
// (쨡; 쨡; 쨡; 쨡; 쨡; ) HANGUL SYLLABLE JJYALT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA21 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA21 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA21 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_130)
{
// CA22;CA22;110D 1163 11B5;CA22;110D 1163 11B5;
// (쨢; 쨢; 쨢; 쨢; 쨢; ) HANGUL SYLLABLE JJYALP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA22 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA22 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA22 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_131)
{
// CA23;CA23;110D 1163 11B6;CA23;110D 1163 11B6;
// (쨣; 쨣; 쨣; 쨣; 쨣; ) HANGUL SYLLABLE JJYALH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA23 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA23 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA23 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_132)
{
// CA24;CA24;110D 1163 11B7;CA24;110D 1163 11B7;
// (쨤; 쨤; 쨤; 쨤; 쨤; ) HANGUL SYLLABLE JJYAM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA24 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA24 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA24 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_133)
{
// CA25;CA25;110D 1163 11B8;CA25;110D 1163 11B8;
// (쨥; 쨥; 쨥; 쨥; 쨥; ) HANGUL SYLLABLE JJYAB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA25 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA25 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA25 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_134)
{
// CA26;CA26;110D 1163 11B9;CA26;110D 1163 11B9;
// (쨦; 쨦; 쨦; 쨦; 쨦; ) HANGUL SYLLABLE JJYABS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA26 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA26 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA26 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_135)
{
// CA27;CA27;110D 1163 11BA;CA27;110D 1163 11BA;
// (쨧; 쨧; 쨧; 쨧; 쨧; ) HANGUL SYLLABLE JJYAS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA27 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA27 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA27 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_136)
{
// CA28;CA28;110D 1163 11BB;CA28;110D 1163 11BB;
// (쨨; 쨨; 쨨; 쨨; 쨨; ) HANGUL SYLLABLE JJYASS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA28 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA28 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA28 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_137)
{
// CA29;CA29;110D 1163 11BC;CA29;110D 1163 11BC;
// (쨩; 쨩; 쨩; 쨩; 쨩; ) HANGUL SYLLABLE JJYANG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA29 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA29 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA29 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_138)
{
// CA2A;CA2A;110D 1163 11BD;CA2A;110D 1163 11BD;
// (쨪; 쨪; 쨪; 쨪; 쨪; ) HANGUL SYLLABLE JJYAJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_139)
{
// CA2B;CA2B;110D 1163 11BE;CA2B;110D 1163 11BE;
// (쨫; 쨫; 쨫; 쨫; 쨫; ) HANGUL SYLLABLE JJYAC
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_140)
{
// CA2C;CA2C;110D 1163 11BF;CA2C;110D 1163 11BF;
// (쨬; 쨬; 쨬; 쨬; 쨬; ) HANGUL SYLLABLE JJYAK
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2C }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2C }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_141)
{
// CA2D;CA2D;110D 1163 11C0;CA2D;110D 1163 11C0;
// (쨭; 쨭; 쨭; 쨭; 쨭; ) HANGUL SYLLABLE JJYAT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_142)
{
// CA2E;CA2E;110D 1163 11C1;CA2E;110D 1163 11C1;
// (쨮; 쨮; 쨮; 쨮; 쨮; ) HANGUL SYLLABLE JJYAP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_143)
{
// CA2F;CA2F;110D 1163 11C2;CA2F;110D 1163 11C2;
// (쨯; 쨯; 쨯; 쨯; 쨯; ) HANGUL SYLLABLE JJYAH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA2F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA2F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1163, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA2F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1163, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_144)
{
// CA30;CA30;110D 1164;CA30;110D 1164;
// (쨰; 쨰; 쨰; 쨰; 쨰; ) HANGUL SYLLABLE JJYAE
{
std::array<uint32_t, 1> const c1 = {{ 0xCA30 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA30 }};
std::array<uint32_t, 2> const c3 = {{ 0x110D, 0x1164 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA30 }};
std::array<uint32_t, 2> const c5 = {{ 0x110D, 0x1164 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_145)
{
// CA31;CA31;110D 1164 11A8;CA31;110D 1164 11A8;
// (쨱; 쨱; 쨱; 쨱; 쨱; ) HANGUL SYLLABLE JJYAEG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA31 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA31 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA31 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_146)
{
// CA32;CA32;110D 1164 11A9;CA32;110D 1164 11A9;
// (쨲; 쨲; 쨲; 쨲; 쨲; ) HANGUL SYLLABLE JJYAEGG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA32 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA32 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA32 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_147)
{
// CA33;CA33;110D 1164 11AA;CA33;110D 1164 11AA;
// (쨳; 쨳; 쨳; 쨳; 쨳; ) HANGUL SYLLABLE JJYAEGS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA33 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA33 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA33 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_148)
{
// CA34;CA34;110D 1164 11AB;CA34;110D 1164 11AB;
// (쨴; 쨴; 쨴; 쨴; 쨴; ) HANGUL SYLLABLE JJYAEN
{
std::array<uint32_t, 1> const c1 = {{ 0xCA34 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA34 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA34 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_149)
{
// CA35;CA35;110D 1164 11AC;CA35;110D 1164 11AC;
// (쨵; 쨵; 쨵; 쨵; 쨵; ) HANGUL SYLLABLE JJYAENJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA35 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA35 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA35 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_150)
{
// CA36;CA36;110D 1164 11AD;CA36;110D 1164 11AD;
// (쨶; 쨶; 쨶; 쨶; 쨶; ) HANGUL SYLLABLE JJYAENH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA36 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA36 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA36 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_151)
{
// CA37;CA37;110D 1164 11AE;CA37;110D 1164 11AE;
// (쨷; 쨷; 쨷; 쨷; 쨷; ) HANGUL SYLLABLE JJYAED
{
std::array<uint32_t, 1> const c1 = {{ 0xCA37 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA37 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA37 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_152)
{
// CA38;CA38;110D 1164 11AF;CA38;110D 1164 11AF;
// (쨸; 쨸; 쨸; 쨸; 쨸; ) HANGUL SYLLABLE JJYAEL
{
std::array<uint32_t, 1> const c1 = {{ 0xCA38 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA38 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA38 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_153)
{
// CA39;CA39;110D 1164 11B0;CA39;110D 1164 11B0;
// (쨹; 쨹; 쨹; 쨹; 쨹; ) HANGUL SYLLABLE JJYAELG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA39 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA39 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA39 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_154)
{
// CA3A;CA3A;110D 1164 11B1;CA3A;110D 1164 11B1;
// (쨺; 쨺; 쨺; 쨺; 쨺; ) HANGUL SYLLABLE JJYAELM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_155)
{
// CA3B;CA3B;110D 1164 11B2;CA3B;110D 1164 11B2;
// (쨻; 쨻; 쨻; 쨻; 쨻; ) HANGUL SYLLABLE JJYAELB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_156)
{
// CA3C;CA3C;110D 1164 11B3;CA3C;110D 1164 11B3;
// (쨼; 쨼; 쨼; 쨼; 쨼; ) HANGUL SYLLABLE JJYAELS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3C }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3C }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_157)
{
// CA3D;CA3D;110D 1164 11B4;CA3D;110D 1164 11B4;
// (쨽; 쨽; 쨽; 쨽; 쨽; ) HANGUL SYLLABLE JJYAELT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_158)
{
// CA3E;CA3E;110D 1164 11B5;CA3E;110D 1164 11B5;
// (쨾; 쨾; 쨾; 쨾; 쨾; ) HANGUL SYLLABLE JJYAELP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_159)
{
// CA3F;CA3F;110D 1164 11B6;CA3F;110D 1164 11B6;
// (쨿; 쨿; 쨿; 쨿; 쨿; ) HANGUL SYLLABLE JJYAELH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA3F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA3F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA3F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_160)
{
// CA40;CA40;110D 1164 11B7;CA40;110D 1164 11B7;
// (쩀; 쩀; 쩀; 쩀; 쩀; ) HANGUL SYLLABLE JJYAEM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA40 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA40 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA40 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_161)
{
// CA41;CA41;110D 1164 11B8;CA41;110D 1164 11B8;
// (쩁; 쩁; 쩁; 쩁; 쩁; ) HANGUL SYLLABLE JJYAEB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA41 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA41 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA41 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_162)
{
// CA42;CA42;110D 1164 11B9;CA42;110D 1164 11B9;
// (쩂; 쩂; 쩂; 쩂; 쩂; ) HANGUL SYLLABLE JJYAEBS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA42 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA42 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA42 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_163)
{
// CA43;CA43;110D 1164 11BA;CA43;110D 1164 11BA;
// (쩃; 쩃; 쩃; 쩃; 쩃; ) HANGUL SYLLABLE JJYAES
{
std::array<uint32_t, 1> const c1 = {{ 0xCA43 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA43 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA43 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_164)
{
// CA44;CA44;110D 1164 11BB;CA44;110D 1164 11BB;
// (쩄; 쩄; 쩄; 쩄; 쩄; ) HANGUL SYLLABLE JJYAESS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA44 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA44 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA44 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_165)
{
// CA45;CA45;110D 1164 11BC;CA45;110D 1164 11BC;
// (쩅; 쩅; 쩅; 쩅; 쩅; ) HANGUL SYLLABLE JJYAENG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA45 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA45 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA45 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_166)
{
// CA46;CA46;110D 1164 11BD;CA46;110D 1164 11BD;
// (쩆; 쩆; 쩆; 쩆; 쩆; ) HANGUL SYLLABLE JJYAEJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA46 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA46 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA46 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_167)
{
// CA47;CA47;110D 1164 11BE;CA47;110D 1164 11BE;
// (쩇; 쩇; 쩇; 쩇; 쩇; ) HANGUL SYLLABLE JJYAEC
{
std::array<uint32_t, 1> const c1 = {{ 0xCA47 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA47 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA47 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_168)
{
// CA48;CA48;110D 1164 11BF;CA48;110D 1164 11BF;
// (쩈; 쩈; 쩈; 쩈; 쩈; ) HANGUL SYLLABLE JJYAEK
{
std::array<uint32_t, 1> const c1 = {{ 0xCA48 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA48 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA48 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_169)
{
// CA49;CA49;110D 1164 11C0;CA49;110D 1164 11C0;
// (쩉; 쩉; 쩉; 쩉; 쩉; ) HANGUL SYLLABLE JJYAET
{
std::array<uint32_t, 1> const c1 = {{ 0xCA49 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA49 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA49 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_170)
{
// CA4A;CA4A;110D 1164 11C1;CA4A;110D 1164 11C1;
// (쩊; 쩊; 쩊; 쩊; 쩊; ) HANGUL SYLLABLE JJYAEP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_171)
{
// CA4B;CA4B;110D 1164 11C2;CA4B;110D 1164 11C2;
// (쩋; 쩋; 쩋; 쩋; 쩋; ) HANGUL SYLLABLE JJYAEH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1164, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1164, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_172)
{
// CA4C;CA4C;110D 1165;CA4C;110D 1165;
// (쩌; 쩌; 쩌; 쩌; 쩌; ) HANGUL SYLLABLE JJEO
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4C }};
std::array<uint32_t, 2> const c3 = {{ 0x110D, 0x1165 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4C }};
std::array<uint32_t, 2> const c5 = {{ 0x110D, 0x1165 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_173)
{
// CA4D;CA4D;110D 1165 11A8;CA4D;110D 1165 11A8;
// (쩍; 쩍; 쩍; 쩍; 쩍; ) HANGUL SYLLABLE JJEOG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_174)
{
// CA4E;CA4E;110D 1165 11A9;CA4E;110D 1165 11A9;
// (쩎; 쩎; 쩎; 쩎; 쩎; ) HANGUL SYLLABLE JJEOGG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_175)
{
// CA4F;CA4F;110D 1165 11AA;CA4F;110D 1165 11AA;
// (쩏; 쩏; 쩏; 쩏; 쩏; ) HANGUL SYLLABLE JJEOGS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA4F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA4F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA4F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_176)
{
// CA50;CA50;110D 1165 11AB;CA50;110D 1165 11AB;
// (쩐; 쩐; 쩐; 쩐; 쩐; ) HANGUL SYLLABLE JJEON
{
std::array<uint32_t, 1> const c1 = {{ 0xCA50 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA50 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA50 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_177)
{
// CA51;CA51;110D 1165 11AC;CA51;110D 1165 11AC;
// (쩑; 쩑; 쩑; 쩑; 쩑; ) HANGUL SYLLABLE JJEONJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA51 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA51 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA51 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_178)
{
// CA52;CA52;110D 1165 11AD;CA52;110D 1165 11AD;
// (쩒; 쩒; 쩒; 쩒; 쩒; ) HANGUL SYLLABLE JJEONH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA52 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA52 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA52 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_179)
{
// CA53;CA53;110D 1165 11AE;CA53;110D 1165 11AE;
// (쩓; 쩓; 쩓; 쩓; 쩓; ) HANGUL SYLLABLE JJEOD
{
std::array<uint32_t, 1> const c1 = {{ 0xCA53 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA53 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA53 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_180)
{
// CA54;CA54;110D 1165 11AF;CA54;110D 1165 11AF;
// (쩔; 쩔; 쩔; 쩔; 쩔; ) HANGUL SYLLABLE JJEOL
{
std::array<uint32_t, 1> const c1 = {{ 0xCA54 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA54 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA54 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11AF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_181)
{
// CA55;CA55;110D 1165 11B0;CA55;110D 1165 11B0;
// (쩕; 쩕; 쩕; 쩕; 쩕; ) HANGUL SYLLABLE JJEOLG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA55 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA55 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA55 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_182)
{
// CA56;CA56;110D 1165 11B1;CA56;110D 1165 11B1;
// (쩖; 쩖; 쩖; 쩖; 쩖; ) HANGUL SYLLABLE JJEOLM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA56 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA56 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA56 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_183)
{
// CA57;CA57;110D 1165 11B2;CA57;110D 1165 11B2;
// (쩗; 쩗; 쩗; 쩗; 쩗; ) HANGUL SYLLABLE JJEOLB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA57 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA57 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA57 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_184)
{
// CA58;CA58;110D 1165 11B3;CA58;110D 1165 11B3;
// (쩘; 쩘; 쩘; 쩘; 쩘; ) HANGUL SYLLABLE JJEOLS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA58 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA58 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA58 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_185)
{
// CA59;CA59;110D 1165 11B4;CA59;110D 1165 11B4;
// (쩙; 쩙; 쩙; 쩙; 쩙; ) HANGUL SYLLABLE JJEOLT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA59 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA59 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA59 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_186)
{
// CA5A;CA5A;110D 1165 11B5;CA5A;110D 1165 11B5;
// (쩚; 쩚; 쩚; 쩚; 쩚; ) HANGUL SYLLABLE JJEOLP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5A }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5A }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5A }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_187)
{
// CA5B;CA5B;110D 1165 11B6;CA5B;110D 1165 11B6;
// (쩛; 쩛; 쩛; 쩛; 쩛; ) HANGUL SYLLABLE JJEOLH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5B }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5B }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5B }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_188)
{
// CA5C;CA5C;110D 1165 11B7;CA5C;110D 1165 11B7;
// (쩜; 쩜; 쩜; 쩜; 쩜; ) HANGUL SYLLABLE JJEOM
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5C }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5C }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5C }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_189)
{
// CA5D;CA5D;110D 1165 11B8;CA5D;110D 1165 11B8;
// (쩝; 쩝; 쩝; 쩝; 쩝; ) HANGUL SYLLABLE JJEOB
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5D }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5D }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5D }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_190)
{
// CA5E;CA5E;110D 1165 11B9;CA5E;110D 1165 11B9;
// (쩞; 쩞; 쩞; 쩞; 쩞; ) HANGUL SYLLABLE JJEOBS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5E }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5E }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5E }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_191)
{
// CA5F;CA5F;110D 1165 11BA;CA5F;110D 1165 11BA;
// (쩟; 쩟; 쩟; 쩟; 쩟; ) HANGUL SYLLABLE JJEOS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA5F }};
std::array<uint32_t, 1> const c2 = {{ 0xCA5F }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xCA5F }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BA }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_192)
{
// CA60;CA60;110D 1165 11BB;CA60;110D 1165 11BB;
// (쩠; 쩠; 쩠; 쩠; 쩠; ) HANGUL SYLLABLE JJEOSS
{
std::array<uint32_t, 1> const c1 = {{ 0xCA60 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA60 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xCA60 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BB }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_193)
{
// CA61;CA61;110D 1165 11BC;CA61;110D 1165 11BC;
// (쩡; 쩡; 쩡; 쩡; 쩡; ) HANGUL SYLLABLE JJEONG
{
std::array<uint32_t, 1> const c1 = {{ 0xCA61 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA61 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xCA61 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BC }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_194)
{
// CA62;CA62;110D 1165 11BD;CA62;110D 1165 11BD;
// (쩢; 쩢; 쩢; 쩢; 쩢; ) HANGUL SYLLABLE JJEOJ
{
std::array<uint32_t, 1> const c1 = {{ 0xCA62 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA62 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xCA62 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BD }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_195)
{
// CA63;CA63;110D 1165 11BE;CA63;110D 1165 11BE;
// (쩣; 쩣; 쩣; 쩣; 쩣; ) HANGUL SYLLABLE JJEOC
{
std::array<uint32_t, 1> const c1 = {{ 0xCA63 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA63 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xCA63 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BE }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_196)
{
// CA64;CA64;110D 1165 11BF;CA64;110D 1165 11BF;
// (쩤; 쩤; 쩤; 쩤; 쩤; ) HANGUL SYLLABLE JJEOK
{
std::array<uint32_t, 1> const c1 = {{ 0xCA64 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA64 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xCA64 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11BF }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_197)
{
// CA65;CA65;110D 1165 11C0;CA65;110D 1165 11C0;
// (쩥; 쩥; 쩥; 쩥; 쩥; ) HANGUL SYLLABLE JJEOT
{
std::array<uint32_t, 1> const c1 = {{ 0xCA65 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA65 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA65 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_198)
{
// CA66;CA66;110D 1165 11C1;CA66;110D 1165 11C1;
// (쩦; 쩦; 쩦; 쩦; 쩦; ) HANGUL SYLLABLE JJEOP
{
std::array<uint32_t, 1> const c1 = {{ 0xCA66 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA66 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA66 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
TEST(normalization, nfc_050_199)
{
// CA67;CA67;110D 1165 11C2;CA67;110D 1165 11C2;
// (쩧; 쩧; 쩧; 쩧; 쩧; ) HANGUL SYLLABLE JJEOH
{
std::array<uint32_t, 1> const c1 = {{ 0xCA67 }};
std::array<uint32_t, 1> const c2 = {{ 0xCA67 }};
std::array<uint32_t, 3> const c3 = {{ 0x110D, 0x1165, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xCA67 }};
std::array<uint32_t, 3> const c5 = {{ 0x110D, 0x1165, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized_nfc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized_nfc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfkc(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized_nfd(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized_nfkd(c5.begin(), c5.end()));
{
boost::text::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c2.size());
auto c2_it = c2.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c2_it) << "iteration " << i;
++c2_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
{
boost::text::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize_to_nfc(str);
boost::text::utf32_range utf32_range(str);
EXPECT_EQ(std::distance(utf32_range.begin(), utf32_range.end()), c4.size());
auto c4_it = c4.begin();
int i = 0;
for (auto x : utf32_range) {
EXPECT_EQ(x, *c4_it) << "iteration " << i;
++c4_it;
++i;
}
}
}
}
| [
"whatwasthataddress@gmail.com"
] | whatwasthataddress@gmail.com |
b1b3b52b4fb13414465e04efd1ad47ab87d4460d | 6a69d57c782e0b1b993e876ad4ca2927a5f2e863 | /vendor/samsung/common/packages/apps/SBrowser/src/mojo/shell/desktop/mojo_main.cc | 9be96472ab147eb097639dd3ee393772639ca17c | [
"BSD-3-Clause"
] | permissive | duki994/G900H-Platform-XXU1BOA7 | c8411ef51f5f01defa96b3381f15ea741aa5bce2 | 4f9307e6ef21893c9a791c96a500dfad36e3b202 | refs/heads/master | 2020-05-16T20:57:07.585212 | 2015-05-11T11:03:16 | 2015-05-11T11:03:16 | 35,418,464 | 2 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 764 | cc | // Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
#include "mojo/shell/run.h"
#include "ui/gl/gl_surface.h"
int main(int argc, char** argv) {
base::AtExitManager at_exit;
CommandLine::Init(argc, argv);
mojo::shell::InitializeLogging();
gfx::GLSurface::InitializeOneOff();
base::MessageLoop message_loop;
mojo::shell::Context context;
message_loop.PostTask(FROM_HERE, base::Bind(mojo::shell::Run, &context));
message_loop.Run();
return 0;
}
| [
"duki994@gmail.com"
] | duki994@gmail.com |
c7cdd8555a1499c8907e3ec8092ecd315fe64eb6 | bd2078d14897d0d2c309b0c464e8e6f6d30ffcd6 | /src/device_trezor/device_trezor_base.cpp | 35605024ae516e4f531a7b642fd704920d5ce587 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | tritonix/triton-first | 28d74a384c59445a9c78532f37e4fac0fe747865 | 5b17b1ea1d5a1044b837fb4f2c01d7e68ebb85a7 | refs/heads/master | 2020-04-08T02:29:51.440698 | 2018-11-24T14:03:54 | 2018-11-24T14:03:54 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,922 | cpp | // Copyright (c) 2017-2018, Triton Developers
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "device_trezor_base.hpp"
namespace hw {
namespace trezor {
#if WITH_DEVICE_TREZOR
#undef TRITON_DEFAULT_LOG_CATEGORY
#define TRITON_DEFAULT_LOG_CATEGORY "device.trezor"
std::shared_ptr<google::protobuf::Message> trezor_protocol_callback::on_button_request(const messages::common::ButtonRequest * msg){
MDEBUG("on_button_request");
device.on_button_request();
return std::make_shared<messages::common::ButtonAck>();
}
std::shared_ptr<google::protobuf::Message> trezor_protocol_callback::on_pin_matrix_request(const messages::common::PinMatrixRequest * msg){
MDEBUG("on_pin_request");
epee::wipeable_string pin;
device.on_pin_request(pin);
auto resp = std::make_shared<messages::common::PinMatrixAck>();
resp->set_pin(pin.data(), pin.size());
return resp;
}
std::shared_ptr<google::protobuf::Message> trezor_protocol_callback::on_passphrase_request(const messages::common::PassphraseRequest * msg){
MDEBUG("on_passhprase_request");
epee::wipeable_string passphrase;
device.on_passphrase_request(msg->on_device(), passphrase);
auto resp = std::make_shared<messages::common::PassphraseAck>();
if (!msg->on_device()){
resp->set_passphrase(passphrase.data(), passphrase.size());
}
return resp;
}
std::shared_ptr<google::protobuf::Message> trezor_protocol_callback::on_passphrase_state_request(const messages::common::PassphraseStateRequest * msg){
MDEBUG("on_passhprase_state_request");
device.on_passphrase_state_request(msg->state());
return std::make_shared<messages::common::PassphraseStateAck>();
}
const uint32_t device_trezor_base::DEFAULT_BIP44_PATH[] = {0x8000002c, 0x80000080, 0x80000000};
device_trezor_base::device_trezor_base() {
}
device_trezor_base::~device_trezor_base() {
try {
disconnect();
release();
} catch(std::exception const& e){
MERROR("Could not disconnect and release: " << e.what());
}
}
/* ======================================================================= */
/* SETUP/TEARDOWN */
/* ======================================================================= */
bool device_trezor_base::reset() {
return false;
}
bool device_trezor_base::set_name(const std::string & name) {
this->full_name = name;
this->name = "";
auto delim = name.find(':');
if (delim != std::string::npos && delim + 1 < name.length()) {
this->name = name.substr(delim + 1);
}
return true;
}
const std::string device_trezor_base::get_name() const {
if (this->full_name.empty()) {
return std::string("<disconnected:").append(this->name).append(">");
}
return this->full_name;
}
bool device_trezor_base::init() {
if (!release()){
MERROR("Release failed");
return false;
}
if (!m_protocol_callback){
m_protocol_callback = std::make_shared<trezor_protocol_callback>(*this);
}
return true;
}
bool device_trezor_base::release() {
try {
disconnect();
return true;
} catch(std::exception const& e){
MERROR("Release exception: " << e.what());
return false;
}
}
bool device_trezor_base::connect() {
disconnect();
// Enumerate all available devices
try {
hw::trezor::t_transport_vect trans;
MDEBUG("Enumerating Trezor devices...");
enumerate(trans);
MDEBUG("Enumeration yielded " << trans.size() << " devices");
for (auto &cur : trans) {
MDEBUG(" device: " << *(cur.get()));
std::string cur_path = cur->get_path();
if (boost::starts_with(cur_path, this->name)) {
MDEBUG("Device Match: " << cur_path);
m_transport = cur;
break;
}
}
if (!m_transport) {
MERROR("No matching Trezor device found. Device specifier: \"" + this->name + "\"");
return false;
}
m_transport->open();
return true;
} catch(std::exception const& e){
MERROR("Open exception: " << e.what());
return false;
}
}
bool device_trezor_base::disconnect() {
if (m_transport){
try {
m_transport->close();
m_transport = nullptr;
} catch(std::exception const& e){
MERROR("Disconnect exception: " << e.what());
m_transport = nullptr;
return false;
}
}
return true;
}
/* ======================================================================= */
/* LOCKER */
/* ======================================================================= */
//lock the device for a long sequence
void device_trezor_base::lock() {
MTRACE("Ask for LOCKING for device " << this->name << " in thread ");
device_locker.lock();
MTRACE("Device " << this->name << " LOCKed");
}
//lock the device for a long sequence
bool device_trezor_base::try_lock() {
MTRACE("Ask for LOCKING(try) for device " << this->name << " in thread ");
bool r = device_locker.try_lock();
if (r) {
MTRACE("Device " << this->name << " LOCKed(try)");
} else {
MDEBUG("Device " << this->name << " not LOCKed(try)");
}
return r;
}
//unlock the device
void device_trezor_base::unlock() {
MTRACE("Ask for UNLOCKING for device " << this->name << " in thread ");
device_locker.unlock();
MTRACE("Device " << this->name << " UNLOCKed");
}
/* ======================================================================= */
/* Helpers */
/* ======================================================================= */
void device_trezor_base::require_connected(){
if (!m_transport){
throw exc::NotConnectedException();
}
}
void device_trezor_base::call_ping_unsafe(){
auto pingMsg = std::make_shared<messages::management::Ping>();
pingMsg->set_message("PING");
auto success = this->client_exchange<messages::common::Success>(pingMsg); // messages::MessageType_Success
MDEBUG("Ping response " << success->message());
(void)success;
}
void device_trezor_base::test_ping(){
require_connected();
try {
this->call_ping_unsafe();
} catch(exc::TrezorException const& e){
MINFO("Trezor does not respond: " << e.what());
throw exc::DeviceNotResponsiveException(std::string("Trezor not responding: ") + e.what());
}
}
/* ======================================================================= */
/* TREZOR PROTOCOL */
/* ======================================================================= */
bool device_trezor_base::ping() {
AUTO_LOCK_CMD();
if (!m_transport){
MINFO("Ping failed, device not connected");
return false;
}
try {
this->call_ping_unsafe();
return true;
} catch(std::exception const& e) {
MERROR("Ping failed, exception thrown " << e.what());
} catch(...){
MERROR("Ping failed, general exception thrown" << boost::current_exception_diagnostic_information());
}
return false;
}
void device_trezor_base::on_button_request()
{
if (m_callback){
m_callback->on_button_request();
}
}
void device_trezor_base::on_pin_request(epee::wipeable_string & pin)
{
if (m_callback){
m_callback->on_pin_request(pin);
}
}
void device_trezor_base::on_passphrase_request(bool on_device, epee::wipeable_string & passphrase)
{
if (m_callback){
m_callback->on_passphrase_request(on_device, passphrase);
}
}
void device_trezor_base::on_passphrase_state_request(const std::string & state)
{
if (m_callback){
m_callback->on_passphrase_state_request(state);
}
}
#endif //WITH_DEVICE_TREZOR
}}
| [
"dant00300@gmail.com"
] | dant00300@gmail.com |
25f6e7d72cd0061fbee32c8feebcf06689729832 | a59718794651c848f125381858a422fe4a4e64d7 | /STM32F0-base/motor-coffee-machine/motorADC.cpp | 75fdc74c6d7cd76eca9eba9570da43a4c0190089 | [] | no_license | QuangNT8/gitworks | 407618d307026e21a525eee22db05d8b827d7656 | 9ead50df90e70d9ca878c689fd49f59e78a8a248 | refs/heads/master | 2023-03-07T13:07:15.109801 | 2021-12-10T00:55:26 | 2021-12-10T00:55:26 | 123,459,868 | 0 | 5 | null | 2023-02-28T00:26:49 | 2018-03-01T16:16:57 | C | UTF-8 | C++ | false | false | 2,359 | cpp | #include "motor.h"
void step::Motor::initADC_()
{
RCC->AHBENR |= RCC_AHBENR_GPIOCEN;
/*********************************
* ADC
* ADC_CHSELR_CHSEL10 -> IA (readADC[1])(PC0)
* ADC_CHSELR_CHSEL11 -> IB (readADC[2])(PC1)
* ********************************
*/
GPIOC->MODER |= (GPIO_MODER_MODER0 | GPIO_MODER_MODER1);
/*ADC Clock selection*/
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC->CR2 |= RCC_CR2_HSI14ON;/*HSI14*/
while ((RCC->CR2 & RCC_CR2_HSI14RDY) == 0){}
/*ADC enable sequence*/
if ((ADC1->ISR & ADC_ISR_ADRDY) != 0)
{
ADC1->ISR |= ADC_ISR_ADRDY;
}
ADC1->CR |= ADC_CR_ADEN;
while ((ADC1->ISR & ADC_ISR_ADRDY) == 0){}
/*
* Single conversion sequence
*/
ADC1->CHSELR = ADC_CHSELR_CHSEL10 | ADC_CHSELR_CHSEL11;
ADC1->SMPR |= ADC_SMPR1_SMPR_0;/*001 7.5 ADC clock cycles (7.5*1/14 = 0.54us <=> 1 chanel)*/
ADC1->CFGR1 &= ~ADC_CFGR1_RES; /*00: 12 bits ADC conversion time: 1.0 µs for 12-bit resolution <=> 1 chanel)*/
/*DMA circular mode*/
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
ADC1->CFGR1 |= ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG;
DMA1_Channel1->CPAR = (uint32_t) (&(ADC1->DR));
DMA1_Channel1->CMAR = (uint32_t)(adcBuffer_);
DMA1_Channel1->CNDTR = 2;
DMA1_Channel1->CCR |= DMA_CCR_MINC | DMA_CCR_MSIZE_0 | DMA_CCR_PSIZE_0 | DMA_CCR_CIRC | DMA_CCR_TCIE;
DMA1_Channel1->CCR |= DMA_CCR_EN;
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
NVIC_SetPriority(DMA1_Channel1_IRQn,1);
/*begin test*/
ADC1->CFGR1 |= ADC_CFGR1_EXTEN_0;/*01: Hardware trigger detection on the rising edge*/
ADC1->CFGR1 &= ~(ADC_CFGR1_EXTSEL_0 | ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_2);/*000 TRG0 TIM1_TRGO*/
ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversion */
/*end test*/
}
extern "C" void DMA1_Channel1_IRQHandler(void) //40kHz
{
if( (DMA1->ISR & DMA_ISR_TCIF1) == DMA_ISR_TCIF1 )
{
DMA1->IFCR |= DMA_IFCR_CTCIF1;
step::MOTOR.adcReady();
}
}
#define FILTER_SHIFT 3
void step::Motor::adcReady()
{
ia_ = adcBuffer_[0] - CALIBRATE_ADC;
ib_ = adcBuffer_[1] - CALIBRATE_ADC;
iA_= (AMPE_ZERO*adcBuffer_[0])/CALIBRATE_ADC;
iA_ = 1000*(iA_ - AMPE_ZERO)/ACS712_5A_MV_A;
iB_= (AMPE_ZERO*adcBuffer_[1])/CALIBRATE_ADC;
iB_ = 1000*(iB_ - AMPE_ZERO)/ACS712_5A_MV_A;
}
| [
"nguyentrungquang102@gmail.com"
] | nguyentrungquang102@gmail.com |
2232992918e0cbd1a78509199f3803b9ff4e4f53 | 51037b66998c79a1442add8ed298c9c6e473dcf2 | /Source/Item/Item.cpp | b691d9edcb0aba69ad9f584dd7cb33693dd1c29a | [
"Apache-2.0"
] | permissive | Andres6936/LoX | 3ca7f8d2e1a2e07388f7e1b3b56c8510438fac33 | 5e26ecc8ddb7f43b785a1fa0c7cb87c0691530d3 | refs/heads/master | 2020-06-13T04:01:21.713205 | 2020-05-21T22:03:31 | 2020-05-21T22:03:31 | 194,527,182 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,212 | cpp | #include "Item/Include/Item.hpp"
#include "Include/ItemList.hpp"
UInt Item::GetWeight( ) const
{
return weight;
}
std::string Item::GetName( ) const
{
return name;
}
EItemCategory Item::GetCategory( ) const
{
return category;
}
EItemTypes Item::GetType( ) const
{
return type;
}
ItemPointer Item::Generate( )
{
// Generate number random from 1 to 3.
unsigned int cat = rand( ) % 3 + 1;
Die die = { };
ItemPointer item;
if ( cat == 1 )
{
die.Set( 1, sizeof( armourTemplates ) / sizeof( armourTemplates[ 0 ] ), -1 );
item = std::make_shared <Armour>( armourTemplates[ DieRoll::Roll( die ) ] );
}
else if ( cat == 2 )
{
die.Set( 1, sizeof( weaponTemplates ) / sizeof( weaponTemplates[ 0 ] ), -1 );
item = std::make_shared <Weapon>( weaponTemplates[ DieRoll::Roll( die ) ] );
}
else if ( cat == 3 )
{
die.Set( 1, sizeof( rangedTemplates ) / sizeof( rangedTemplates[ 0 ] ), -1 );
item = std::make_shared <Ranged>( rangedTemplates[ DieRoll::Roll( die ) ] );
}
else
{
item = std::make_shared <Item>( "Nothing", EItemCategory::NONE, ITEM_TYPE_NONE, 0 );
}
return item;
}
| [
"andres6936@live.com"
] | andres6936@live.com |
92fbaf67f4c273185c7de46fbe2899673024ca62 | 30277715a1f006195ae525eb5d74b2da99f6f735 | /benchmarks/locp_benchmark.cc | 8a2a3ebbf722b99dd9bdd68af7ddad6f10bfabe1 | [] | no_license | mchouza/locp | 7e4b0510f1fe218a86b92691e1eb7e6af3172692 | f7ed7644e1a9cea45e4b97ff77833fdce3af443f | refs/heads/master | 2021-01-19T03:31:05.079174 | 2016-08-03T18:37:56 | 2016-08-03T18:37:56 | 52,242,521 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,726 | cc | // Copyright (c) 2016 Mariano M. Chouza
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#include "locp.h"
#include <cstdio>
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Syntax: %s <csv-file>\n", argv[0]);
return 1;
}
try
{
locp::CSVParser<> p(argv[1]);
size_t field_count = 0;
const uint8_t *field_start = nullptr;
const uint8_t *field_end = nullptr;
while (p.get_next_field(field_start, field_end))
field_count++;
printf("%zu\n", field_count);
}
catch (const std::exception &e)
{
fprintf(stderr, "Error: %s\n", e.what());
return 1;
}
return 0;
}
| [
"mchouza@gmail.com"
] | mchouza@gmail.com |
edb0c84a8301eb09d15361c9cea6abd9d04baa08 | 30cc5f2974c519687522bd2126cffb71e8c02d94 | /include/Commons/IStateId.h | 0249413266c111b78293151604eded046a16a180 | [] | no_license | quetslaurent/thewarriorsrest | 8f0f01ce970be464ec7cb51a9f1656821f625740 | 11c043ba3e974bdc236afb367173519591217b21 | refs/heads/main | 2023-01-23T03:06:08.553123 | 2020-11-30T11:06:12 | 2020-11-30T11:06:12 | 301,395,473 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 185 | h | #ifndef ISTATEID_H
#define ISTATEID_H
class IStateId
{
protected:
//state id
const int GAME_STATE =0;
const int BATTLE_STATE =1;
};
#endif // ISTATEID_H
| [
"hagejoey.pro@gmail.com"
] | hagejoey.pro@gmail.com |
f689b5a29d5581d1da8033a2807f61a9fdb5d21d | 19dea7c7335a122ef420795f5a1cbf22943f7116 | /TEST1/TEST1/PrintWebUIDelegate.h | 61e9a45911617a7a0a253b8f8b8a34df605f7447 | [] | no_license | HSHtime/MYWEBKIT | f828a4b1604e397d03cabc026cdf0f8c883c2188 | 8fc4402547a235c5755ccaf48c42976c127e801b | refs/heads/master | 2020-06-03T02:16:22.875741 | 2015-04-03T09:06:36 | 2015-04-03T09:06:36 | 33,355,911 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,105 | h | /*
* Copyright (C) 2009, 2014 Apple Inc. All Rights Reserved.
* Copyright (C) 2009 Brent Fulgham. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PrintWebUIDelegate_h
#define PrintWebUIDelegate_h
#include <WebKit/WebKit.h>
class PrintWebUIDelegate : public IWebUIDelegate {
public:
PrintWebUIDelegate() : m_refCount(1) {}
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
virtual ULONG STDMETHODCALLTYPE AddRef(void);
virtual ULONG STDMETHODCALLTYPE Release(void);
virtual HRESULT STDMETHODCALLTYPE createWebViewWithRequest(IWebView*, IWebURLRequest*, IWebView**);
virtual HRESULT STDMETHODCALLTYPE webViewShow(IWebView*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewClose(IWebView*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewFocus(IWebView*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewUnfocus(IWebView*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewFirstResponder(IWebView*, HWND*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE makeFirstResponder(IWebView*, HWND) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setStatusText(IWebView*, BSTR) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewStatusText(IWebView*, BSTR*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewAreToolbarsVisible(IWebView*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setToolbarsVisible(IWebView*, BOOL) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewIsStatusBarVisible(IWebView*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setStatusBarVisible(IWebView*, BOOL) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewIsResizable(IWebView*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setResizable(IWebView*, BOOL) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setFrame(IWebView*, RECT*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewFrame(IWebView*, RECT*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setContentRect(IWebView*, RECT*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewContentRect(IWebView*, RECT*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE runJavaScriptAlertPanelWithMessage(IWebView*, BSTR);
virtual HRESULT STDMETHODCALLTYPE runJavaScriptConfirmPanelWithMessage(IWebView*, BSTR, BOOL*);
virtual HRESULT STDMETHODCALLTYPE runJavaScriptTextInputPanelWithPrompt(IWebView*, BSTR, BSTR, BSTR*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE runBeforeUnloadConfirmPanelWithMessage(IWebView*, BSTR, IWebFrame*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE runOpenPanelForFileButtonWithResultListener(IWebView*, IWebOpenPanelResultListener*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE mouseDidMoveOverElement(IWebView*, IPropertyBag*, UINT) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE contextMenuItemsForElement(IWebView*, IPropertyBag*, HMENU, HMENU*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE validateUserInterfaceItem(IWebView*, UINT, BOOL, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE shouldPerformAction(IWebView*, UINT, UINT) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE dragDestinationActionMaskForDraggingInfo(IWebView*, IDataObject*, WebDragDestinationAction*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE willPerformDragDestinationAction(IWebView*, WebDragDestinationAction, IDataObject*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE dragSourceActionMaskForPoint(IWebView*, LPPOINT, WebDragSourceAction*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE willPerformDragSourceAction(IWebView*, WebDragSourceAction, LPPOINT, IDataObject*, IDataObject**) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE contextMenuItemSelected(IWebView*, void*, IPropertyBag*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE hasCustomMenuImplementation(BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE trackCustomPopupMenu(IWebView*, HMENU, LPPOINT) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE measureCustomMenuItem(IWebView*, void*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE drawCustomMenuItem(IWebView*, void*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE addCustomMenuDrawingData(IWebView*, HMENU) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE cleanUpCustomMenuDrawingData(IWebView*, HMENU) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE canTakeFocus(IWebView*, BOOL, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE takeFocus(IWebView*, BOOL) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE registerUndoWithTarget(IWebUndoTarget*, BSTR, IUnknown*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE removeAllActionsWithTarget(IWebUndoTarget*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setActionTitle(BSTR) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE undo() { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE redo() { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE canUndo(BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE canRedo(BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE printFrame(IWebView*, IWebFrame *) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE ftpDirectoryTemplatePath(IWebView*, BSTR*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE webViewHeaderHeight(IWebView*, float*);
virtual HRESULT STDMETHODCALLTYPE webViewFooterHeight(IWebView*, float*);
virtual HRESULT STDMETHODCALLTYPE drawHeaderInRect(IWebView*, RECT*, ULONG_PTR);
virtual HRESULT STDMETHODCALLTYPE drawFooterInRect(IWebView*, RECT*, ULONG_PTR, UINT, UINT);
virtual HRESULT STDMETHODCALLTYPE webViewPrintingMarginRect(IWebView*, RECT*);
virtual HRESULT STDMETHODCALLTYPE canRunModal(IWebView*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE createModalDialog(IWebView*, IWebURLRequest*, IWebView**) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE runModal(IWebView*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE isMenuBarVisible(IWebView*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE setMenuBarVisible(IWebView*, BOOL) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE runDatabaseSizeLimitPrompt(IWebView*, BSTR, IWebFrame*, BOOL*) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE paintCustomScrollbar(IWebView*, HDC, RECT, WebScrollBarControlSize, WebScrollbarControlState, WebScrollbarControlPart, BOOL, float, float, WebScrollbarControlPartMask) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE paintCustomScrollCorner(IWebView*, HDC, RECT) { return E_NOTIMPL; }
private:
int m_refCount;
};
#endif
| [
"747423692@qq.com"
] | 747423692@qq.com |
19133035209c255629bba1ea44430abbdbd724a8 | 7ed72791fd85f28110c49f84af01ea7b76c3e32a | /src/asr/triglm.h | 783d7cb9c5513c206f3fa76a2ff4aa8d456ee722 | [
"Apache-2.0"
] | permissive | wintrode/catlm | e9139620adbbad4da0b97157b0a42225dea38767 | b699fdf548a3137773dd9a0b6bd867a6bfc29182 | refs/heads/master | 2016-09-15T06:04:32.387172 | 2016-04-21T19:50:05 | 2016-04-21T19:50:05 | 35,110,547 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,234 | h | // asr/nbest.h
// Copyright 2015 Jonathan Wintrode
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
#ifndef CATLM_ASR_TRIGLM_H
#define CATLM_ASR_TRIGLM_H
#include <vector>
#include <map>
#include <stdio.h>
#include "../utils/zlibutil.h"
#include "../utils/vocab_trie.h"
#include "../classifiers/perceptron.h"
#define TRIGLM_VER 1
namespace catlm {
typedef struct _latarc {
int start;
int end;
int wid;
int len;
double cost;
} latarc;
class NbestUtt {
public:
std::vector<int> wids;
std::vector<double> scores;
std::vector<int> lens;
};
class TriggerLM {
private:
VocabTrie &vt;
int order;
int min_order;
string lastkey;
string current_key;
bool use_triggers;
Perceptron p;
bool saveUtts;
bool trigOnly;
int ngram_count;
int num_utts;
std::vector<NbestUtt > utts;
int lc;
int trigger_count;
double lambda;
int vsize;
public:
TriggerLM(VocabTrie &vt, int _order, int _min_order=1, int trig_ngram=0, bool fullng=false);
~TriggerLM();
int get_ngram_count() { return ngram_count; }
int get_ngram(int ngid, std::vector<std::string> & out, std::vector<int> &idout) {
vt.get_ngram(ngid, out, idout);
return out.size();
}
int get_ngram_id(std::vector<std::string> &words, int pos, int len) {
return vt.get_id(words, pos, len);
}
//int get_ngram_id(std::list<int> &words, int pos, int len) {
// return vt.get_id(words, pos, len);
//}
void reset_counters();
int get_pcorrect() {
return p.ccorrect;
}
int get_ptotal() {
return p.tclass;
}
double get_alpha(int fid) {
return p.get_alpha(fid);
}
int read_nbest_feats(FILE *infile, gzFile infd,
std::vector<std::map<int, double> > &uvecs,
std::vector<double> &scores,
std::map<int, double> &hist,
std::vector<std::vector<int> > *nbestlist);
int read_lattice_feats(FILE *infile, gzFile infd,
std::vector<std::map<int, double> > &uvecs,
std::vector<latarc> &arcs,
std::map<int, double> &hist,
std::map<int, std::string> *vmap) ;
string &get_key() { return current_key; }
int train_example(std::map<int, double> &truth,
std::vector<std::map<int, double> > &fvecs,
std::vector<double> &scores);
int train_example_soft(std::vector<std::map<int, double> > &fvecs,
std::vector<double> errs,
std::vector<double> &scores);
int train_example_lattice(std::vector<std::map<int, double> > &fvecs,
std::vector<double> errs);
int rescore(std::vector<std::map<int, double> > &fvecs,
std::vector<double> &scores);
double rescore_lattice(std::map<int, double> &fvec);
void save_utts() { saveUtts=true;}
NbestUtt* get_utt(int i);
void write(const char *file, bool writeng);
bool read(const char* file, const char* lm);
void debug();
void reset();
void setAlpha0(double alpha0) {
p.setFixedA0(true);
p.setAlpha0(alpha0);
}
void setTrigOnly(bool b) {
trigOnly=b;
}
};
void print_vector(FILE*f, std::map<int, double> &vec);
void add_vector(std::map<int, double> &dest, std::map<int, double> &src,
int maxid);
void add_vector(std::map<int, double> &dest, std::map<int, double> &src,
double scalar);
}
#endif
| [
"jcwintr@cs.jhu.edu"
] | jcwintr@cs.jhu.edu |
9989d455b7c53b8f399ba58d7fbc30efec3b82a5 | c1d95debdece07c57115ef4b5ef425c43b7095bd | /src/wpeframework/display.cpp | fa2f577676f63dc59febf4754da8d4c9b98d8ed7 | [] | no_license | valbok/WPEBackend-rdk | 9c3658c616dfa905bdd124f37a8fe3e8a3e1e57e | 7b4c565da3fc513bb9deba7663993e89b1d5714a | refs/heads/master | 2021-01-01T16:22:11.058386 | 2017-07-17T16:05:29 | 2017-07-17T16:05:29 | 97,814,789 | 0 | 0 | null | 2017-07-20T09:08:36 | 2017-07-20T09:08:36 | null | UTF-8 | C++ | false | false | 16,886 | cpp | /*
* Copyright (C) 2017 Metrological
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <wpe/input.h>
#include <wpe/view-backend.h>
#include "display.h"
namespace WPEFramework {
// -----------------------------------------------------------------------------------------
// GLIB framework thread, to keep the wayland loop a-live
// -----------------------------------------------------------------------------------------
class EventSource {
public:
static GSourceFuncs sourceFuncs;
GSource source;
GPollFD pfd;
Wayland::Display* display;
};
GSourceFuncs EventSource::sourceFuncs = {
// prepare
[](GSource* base, gint* timeout) -> gboolean
{
EventSource& source (*(reinterpret_cast<EventSource*>(base)));
// struct wl_display* display = source->display;
*timeout = -1;
// while (wl_display_prepare_read(display) != 0) {
// if (wl_display_dispatch_pending(display) < 0) {
// fprintf(stderr, "Wayland::Display: error in wayland prepare\n");
// return FALSE;
// }
//}
source.display->Flush();
return FALSE;
},
// check
[](GSource* base) -> gboolean
{
EventSource& source (*(reinterpret_cast<EventSource*>(base)));
// struct wl_display* display = source->display;
if (source.pfd.revents & G_IO_IN) {
//if (wl_display_read_events(display) < 0) {
// fprintf(stderr, "Wayland::Display: error in wayland read\n");
// return FALSE;
//}
return TRUE;
} else {
//wl_display_cancel_read(display);
return FALSE;
}
},
// dispatch
[](GSource* base, GSourceFunc, gpointer) -> gboolean
{
EventSource& source (*(reinterpret_cast<EventSource*>(base)));
if (source.pfd.revents & G_IO_IN) {
if (source.display->Process() < 0) {
fprintf(stderr, "Wayland::Display: error in wayland dispatch\n");
return G_SOURCE_REMOVE;
}
}
if (source.pfd.revents & (G_IO_ERR | G_IO_HUP))
return G_SOURCE_REMOVE;
source.pfd.revents = 0;
return G_SOURCE_CONTINUE;
},
nullptr, // finalize
nullptr, // closure_callback
nullptr, // closure_marshall
};
// -----------------------------------------------------------------------------------------
// XKB Keyboard implementation to be hooked up to the wayland abstraction class
// -----------------------------------------------------------------------------------------
static gboolean repeatDelayTimeout(void* data)
{
static_cast<KeyboardHandler*>(data)->RepeatDelayTimeout();
return G_SOURCE_REMOVE;
}
static gboolean repeatRateTimeout(void* data)
{
static_cast<KeyboardHandler*>(data)->RepeatKeyEvent();
return G_SOURCE_CONTINUE;
}
void KeyboardHandler::RepeatKeyEvent()
{
HandleKeyEvent(_repeatData.key, _repeatData.state, _repeatData.time);
}
void KeyboardHandler::RepeatDelayTimeout() {
RepeatKeyEvent();
_repeatData.eventSource = g_timeout_add(_repeatInfo.rate, static_cast<GSourceFunc>(repeatRateTimeout), this);
}
void KeyboardHandler::HandleKeyEvent(const uint32_t key, const IKeyboard::state action, const uint32_t time) {
uint32_t keysym = xkb_state_key_get_one_sym(_xkb.state, key);
uint32_t unicode = xkb_state_key_get_utf32(_xkb.state, key);
if (_xkb.composeState
&& action == IKeyboard::pressed
&& xkb_compose_state_feed(_xkb.composeState, keysym) == XKB_COMPOSE_FEED_ACCEPTED
&& xkb_compose_state_get_status(_xkb.composeState) == XKB_COMPOSE_COMPOSED)
{
keysym = xkb_compose_state_get_one_sym(_xkb.composeState);
unicode = xkb_keysym_to_utf32(keysym);
}
// Send the event, it is complete..
_callback->Key(action == IKeyboard::pressed, keysym, unicode, _xkb.modifiers, time);
}
/* virtual */ void KeyboardHandler::KeyMap(const char information[], const uint16_t size) {
_xkb.keymap = xkb_keymap_new_from_string(_xkb.context, information, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!_xkb.keymap)
return;
_xkb.state = xkb_state_new(_xkb.keymap);
if (!_xkb.state)
return;
_xkb.indexes.control = xkb_keymap_mod_get_index(_xkb.keymap, XKB_MOD_NAME_CTRL);
_xkb.indexes.alt = xkb_keymap_mod_get_index(_xkb.keymap, XKB_MOD_NAME_ALT);
_xkb.indexes.shift = xkb_keymap_mod_get_index(_xkb.keymap, XKB_MOD_NAME_SHIFT);
}
/* virtual */ void KeyboardHandler::Key(const uint32_t key, const IKeyboard::state action, const uint32_t time) {
// IDK.
uint32_t actual_key = key + 8;
HandleKeyEvent(actual_key, action, time);
if (_repeatInfo.rate != 0) {
if (action == IKeyboard::released && _repeatData.key == actual_key) {
if (_repeatData.eventSource)
g_source_remove(_repeatData.eventSource);
_repeatData = { 0, 0, IKeyboard::released, 0 };
} else if (action == IKeyboard::pressed
&& xkb_keymap_key_repeats(_xkb.keymap, actual_key)) {
if (_repeatData.eventSource)
g_source_remove(_repeatData.eventSource);
_repeatData = { actual_key, time, action, g_timeout_add(_repeatInfo.delay, static_cast<GSourceFunc>(repeatDelayTimeout), this) };
}
}
}
/* virtual */ void KeyboardHandler::Modifiers(uint32_t depressedMods, uint32_t latchedMods, uint32_t lockedMods, uint32_t group) {
xkb_state_update_mask(_xkb.state, depressedMods, latchedMods, lockedMods, 0, 0, group);
_xkb.modifiers = 0;
auto component = static_cast<xkb_state_component>(XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
if (xkb_state_mod_index_is_active(_xkb.state, _xkb.indexes.control, component))
_xkb.modifiers |= control;
if (xkb_state_mod_index_is_active(_xkb.state, _xkb.indexes.alt, component))
_xkb.modifiers |= alternate;
if (xkb_state_mod_index_is_active(_xkb.state, _xkb.indexes.shift, component))
_xkb.modifiers |= shift;
}
/* virtual */ void KeyboardHandler::Repeat(int32_t rate, int32_t delay) {
_repeatInfo = { rate, delay };
// A rate of zero disables any repeating.
if (!rate) {
if (_repeatData.eventSource) {
g_source_remove(_repeatData.eventSource);
_repeatData = { 0, 0, IKeyboard::released, 0 };
}
}
}
// -----------------------------------------------------------------------------------------
// Display wrapper around the wayland abstraction class
// -----------------------------------------------------------------------------------------
Display::Display(IPC::Client& ipc)
: m_ipc(ipc)
, m_eventSource(g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)))
, m_keyboard(this)
, m_backend(nullptr)
, m_display(Wayland::Display::Instance()) {
EventSource* source (reinterpret_cast<EventSource*>(m_eventSource));
source->display = &m_display;
source->pfd.fd = m_display.FileDescriptor();
source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
source->pfd.revents = 0;
g_source_add_poll(m_eventSource, &source->pfd);
g_source_set_name(m_eventSource, "[WPE] Display");
g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30);
g_source_set_can_recurse(m_eventSource, TRUE);
g_source_attach(m_eventSource, g_main_context_get_thread_default());
}
Display::~Display() {
}
/* virtual */ void Display::Key (const bool pressed, uint32_t keycode, uint32_t unicode, uint32_t modifiers, uint32_t time)
{
uint8_t wpe_modifiers = 0;
if ((modifiers & KeyboardHandler::control) != 0)
wpe_modifiers |= wpe_input_keyboard_modifier_control;
if ((modifiers & KeyboardHandler::alternate) != 0)
wpe_modifiers |= wpe_input_keyboard_modifier_alt;
if ((modifiers & KeyboardHandler::shift) != 0)
wpe_modifiers |= wpe_input_keyboard_modifier_shift;
struct wpe_input_keyboard_event event = { time, keycode, unicode, pressed, wpe_modifiers };
IPC::Message message;
message.messageCode = MsgType::KEYBOARD;
memcpy( message.messageData, &event, sizeof(event) );
m_ipc.sendMessage(IPC::Message::data(message), IPC::Message::size);
wpe_view_backend_dispatch_keyboard_event(m_backend, &event);
}
void Display::SendEvent( wpe_input_axis_event& event )
{
IPC::Message message;
message.messageCode = MsgType::AXIS;
memcpy( message.messageData, &event, sizeof(event) );
m_ipc.sendMessage(IPC::Message::data(message), IPC::Message::size);
}
void Display::SendEvent( wpe_input_pointer_event& event )
{
IPC::Message message;
message.messageCode = MsgType::POINTER;
memcpy( message.messageData, &event, sizeof(event) );
m_ipc.sendMessage(IPC::Message::data(message), IPC::Message::size);
}
void Display::SendEvent( wpe_input_touch_event& event )
{
IPC::Message message;
message.messageCode = MsgType::TOUCH;
memcpy( message.messageData, &event, sizeof(event) );
m_ipc.sendMessage(IPC::Message::data(message), IPC::Message::size);
}
/* If we have pointer and or touch support in the abstraction layer, link it through like here
static const struct wl_pointer_listener g_pointerListener = {
// enter
[](void* data, struct wl_pointer*, uint32_t serial, struct wl_surface* surface, wl_fixed_t, wl_fixed_t)
{
auto& seatData = *static_cast<Display::SeatData*>(data);
seatData.serial = serial;
auto it = seatData.inputClients.find(surface);
if (it != seatData.inputClients.end())
seatData.pointer.target = *it;
},
// leave
[](void* data, struct wl_pointer*, uint32_t serial, struct wl_surface* surface)
{
auto& seatData = *static_cast<Display::SeatData*>(data);
seatData.serial = serial;
auto it = seatData.inputClients.find(surface);
if (it != seatData.inputClients.end() && seatData.pointer.target.first == it->first)
seatData.pointer.target = { nullptr, nullptr };
},
// motion
[](void* data, struct wl_pointer*, uint32_t time, wl_fixed_t fixedX, wl_fixed_t fixedY)
{
auto x = wl_fixed_to_int(fixedX);
auto y = wl_fixed_to_int(fixedY);
auto& pointer = static_cast<Display::SeatData*>(data)->pointer;
pointer.coords = { x, y };
struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_motion, time, x, y, pointer.button, pointer.state };
EventDispatcher::singleton().sendEvent( event );
if (pointer.target.first) {
struct wpe_view_backend* backend = pointer.target.second;
wpe_view_backend_dispatch_pointer_event(backend, &event);
}
},
// button
[](void* data, struct wl_pointer*, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
{
static_cast<Display::SeatData*>(data)->serial = serial;
if (button >= BTN_MOUSE)
button = button - BTN_MOUSE + 1;
else
button = 0;
auto& pointer = static_cast<Display::SeatData*>(data)->pointer;
auto& coords = pointer.coords;
pointer.button = !!state ? button : 0;
pointer.state = state;
struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_button, time, coords.first, coords.second, button, state };
EventDispatcher::singleton().sendEvent( event );
if (pointer.target.first) {
struct wpe_view_backend* backend = pointer.target.second;
wpe_view_backend_dispatch_pointer_event(backend, &event);
}
},
// axis
[](void* data, struct wl_pointer*, uint32_t time, uint32_t axis, wl_fixed_t value)
{
auto& pointer = static_cast<Display::SeatData*>(data)->pointer;
auto& coords = pointer.coords;
struct wpe_input_axis_event event = { wpe_input_axis_event_type_motion, time, coords.first, coords.second, axis, -wl_fixed_to_int(value) };
EventDispatcher::singleton().sendEvent( event );
if (pointer.target.first) {
struct wpe_view_backend* backend = pointer.target.second;
wpe_view_backend_dispatch_axis_event(backend, &event);
}
},
};
static const struct wl_touch_listener g_touchListener = {
// down
[](void* data, struct wl_touch*, uint32_t serial, uint32_t time, struct wl_surface* surface, int32_t id, wl_fixed_t x, wl_fixed_t y)
{
auto& seatData = *static_cast<Display::SeatData*>(data);
seatData.serial = serial;
int32_t arraySize = std::tuple_size<decltype(seatData.touch.targets)>::value;
if (id < 0 || id >= arraySize)
return;
auto& target = seatData.touch.targets[id];
assert(!target.first && !target.second);
auto it = seatData.inputClients.find(surface);
if (it == seatData.inputClients.end())
return;
target = { surface, it->second };
auto& touchPoints = seatData.touch.touchPoints;
touchPoints[id] = { wpe_input_touch_event_type_down, time, id, wl_fixed_to_int(x), wl_fixed_to_int(y) };
struct wpe_input_touch_event event = { touchPoints.data(), touchPoints.size(), wpe_input_touch_event_type_down, id, time };
struct wpe_view_backend* backend = target.second;
wpe_view_backend_dispatch_touch_event(backend, &event);
},
// up
[](void* data, struct wl_touch*, uint32_t serial, uint32_t time, int32_t id)
{
auto& seatData = *static_cast<Display::SeatData*>(data);
seatData.serial = serial;
int32_t arraySize = std::tuple_size<decltype(seatData.touch.targets)>::value;
if (id < 0 || id >= arraySize)
return;
auto& target = seatData.touch.targets[id];
assert(target.first && target.second);
auto& touchPoints = seatData.touch.touchPoints;
auto& point = touchPoints[id];
point = { wpe_input_touch_event_type_up, time, id, point.x, point.y };
struct wpe_input_touch_event event = { touchPoints.data(), touchPoints.size(), wpe_input_touch_event_type_up, id, time };
struct wpe_view_backend* backend = target.second;
wpe_view_backend_dispatch_touch_event(backend, &event);
point = { wpe_input_touch_event_type_null, 0, 0, 0, 0 };
target = { nullptr, nullptr };
},
// motion
[](void* data, struct wl_touch*, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
{
auto& seatData = *static_cast<Display::SeatData*>(data);
int32_t arraySize = std::tuple_size<decltype(seatData.touch.targets)>::value;
if (id < 0 || id >= arraySize)
return;
auto& target = seatData.touch.targets[id];
assert(target.first && target.second);
auto& touchPoints = seatData.touch.touchPoints;
touchPoints[id] = { wpe_input_touch_event_type_motion, time, id, wl_fixed_to_int(x), wl_fixed_to_int(y) };
struct wpe_input_touch_event event = { touchPoints.data(), touchPoints.size(), wpe_input_touch_event_type_motion, id, time };
struct wpe_view_backend* backend = target.second;
wpe_view_backend_dispatch_touch_event(backend, &event);
},
// frame
[](void*, struct wl_touch*)
{
// FIXME: Dispatching events via frame() would avoid dispatching events
// for every single event that's encapsulated in a frame with multiple
// other events.
},
// cancel
[](void*, struct wl_touch*) { },
};
*/
} // namespace WPEFramework
| [
"pierre@wielders.net"
] | pierre@wielders.net |
65a7608945f3dcd3ab764857394e8f8c581e8d28 | 95e6ab1436de9ba5fcf936639b9bbea0ab5282b5 | /src/InventoryIndexes.h | 8d23bb1ec1722ee0b8d37dd86b4071e54df1470b | [] | no_license | Justice-/ia | c46f3536ad8e80d7a24f69d8921aa3a049c8c177 | 78b7e5d063bef5c1defee7366feb2e2f2a409fbf | refs/heads/master | 2021-01-16T22:50:27.890916 | 2013-06-16T14:50:36 | 2013-06-16T14:50:36 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 588 | h | #ifndef INVENTORY_INDEXES_H
#define INVENTOTY_INDEXES_H
#include <vector>
#include <iostream>
using namespace std;
class InventoryIndexes {
public:
void setIndexes(const bool IS_SLOTS_INCLUDED, const unsigned int nrOfSlots, const vector<unsigned int>& generalSlotsShown);
bool isGeneralInventoryEmpty() const;
char getLastCharIndex() const;
char getCharIndex(const unsigned int i) const;
unsigned int getGeneralSlot(const char charIndex) const;
bool isCharIndexInRange(const char charIndex) const;
private:
vector<char> genInvCharIndexes;
};
#endif
| [
"m.tornq@gmail.com"
] | m.tornq@gmail.com |
1289f60e0534eb6a663d4ce38800565e51c7544d | 2b34800e3538f6d985fde000e35724c6e37439df | /src/language/shi/exception.hh | bc3b86d1e6992f4f08eaefe1e0f5e8efe30f23c5 | [
"MIT"
] | permissive | abyss7/shinobi | 45041a65e0e3125f2212b26b3bd466c8bb21e539 | cb80a009b12f07050cb6acfe067e5fd803671c81 | refs/heads/master | 2021-01-17T13:01:10.203386 | 2017-08-13T03:07:28 | 2017-08-13T03:07:28 | 56,391,751 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,746 | hh | #pragma once
#include <language/shi/token.hh>
namespace shinobi::language::shi {
/*
* Possible syntactic errors are:
* - unexpected symbol: the only case when we know expected symbol is a '"' at
* end of the string.
* - unexpected end of stream: only possible with a string.
* - unexpected token: in many situations we know what we expect.
* - unexpected end of tokens: may happen in a lot of situations too.
*/
class SyntaxError : public std::exception {
public:
explicit SyntaxError(const Location& location) : location_(location) {}
const char* what() const noexcept override;
protected:
inline void SetUnexpected(const String& unexpected) {
unexpected_ = unexpected;
}
inline void SetExpected(const String& expected) { expected_ = expected; }
private:
const Location location_;
mutable String message_;
String unexpected_, expected_;
};
class UnexpectedSymbol : public SyntaxError {
public:
UnexpectedSymbol(const char symbol, const Location& location);
UnexpectedSymbol(const char symbol, const Location& location,
List<char> expected);
};
class UnexpectedToken : public SyntaxError {
public:
explicit UnexpectedToken(const Token& token);
UnexpectedToken(const Token& token, const Token::TypeList& expected);
};
class UnexpectedEndOfTokens : public SyntaxError {
public:
UnexpectedEndOfTokens(const Token::TypeList& expected_types,
const Location& location);
};
class SemanticError : public std::exception {
public:
SemanticError(const Location& location, const String& error_message);
const char* what() const noexcept override;
private:
const Location location_;
String message_;
};
} // namespace shinobi::language::shi
| [
"abyss.7@gmail.com"
] | abyss.7@gmail.com |
867420c7b3ad5e6181e3f5f01b9beceefcf32485 | 5e1f5f2090013041b13d1e280f747aa9f914caa4 | /zircon/kernel/object/msi_allocation.cc | 8f62047f3e83b7ae7233e8e07b4266b256affecf | [
"BSD-2-Clause",
"BSD-3-Clause",
"MIT"
] | permissive | mvanotti/fuchsia-mirror | 477b7d51ae6818e456d5803eea68df35d0d0af88 | 7fb60ae374573299dcb1cc73f950b4f5f981f95c | refs/heads/main | 2022-11-29T08:52:01.817638 | 2021-10-06T05:37:42 | 2021-10-06T05:37:42 | 224,297,435 | 0 | 1 | BSD-2-Clause | 2022-11-21T01:19:37 | 2019-11-26T22:28:11 | C++ | UTF-8 | C++ | false | false | 3,427 | cc | // Copyright 2020 The Fuchsia Authors
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <lib/counters.h>
#include <lib/fit/defer.h>
#include <lib/zircon-internal/thread_annotations.h>
#include <pow2.h>
#include <sys/types.h>
#include <trace.h>
#include <fbl/ref_counted.h>
#include <ktl/bit.h>
#include <ktl/move.h>
#include <object/msi_allocation.h>
KCOUNTER(msi_create_count, "msi.create")
KCOUNTER(msi_destroy_count, "msi.destroy")
#define LOCAL_TRACE 0
zx_status_t MsiAllocation::Create(uint32_t irq_cnt, fbl::RefPtr<MsiAllocation>* obj,
MsiAllocFn msi_alloc_fn, MsiFreeFn msi_free_fn,
MsiSupportedFn msi_support_fn) {
if (!msi_support_fn()) {
return ZX_ERR_NOT_SUPPORTED;
}
msi_block_t block = {};
auto cleanup = fit::defer([&msi_free_fn, &block]() {
if (block.allocated) {
msi_free_fn(&block);
}
});
// Ensure the requested IRQs fit within the mask of permitted IRQs in an
// allocation. MSI allocations must be a power of two.
// MSI supports up to 32, MSI-X supports up to 2048.
if (irq_cnt == 0 || irq_cnt > kMsiAllocationCountMax || !ispow2(irq_cnt)) {
return ZX_ERR_INVALID_ARGS;
}
zx_status_t st = msi_alloc_fn(irq_cnt, false /* can_target_64bit */, false /* is_msix */, &block);
if (st != ZX_OK) {
return st;
}
LTRACEF("MSI Allocation: { tgr_addr = 0x%lx, tgt_data = 0x%08x, base_irq_id = %u }\n",
block.tgt_addr, block.tgt_data, block.base_irq_id);
ktl::array<char, ZX_MAX_NAME_LEN> name;
if (block.num_irq == 1) {
snprintf(name.data(), name.max_size(), "MSI vector %u", block.base_irq_id);
} else {
snprintf(name.data(), name.max_size(), "MSI vectors %u-%u", block.base_irq_id,
block.base_irq_id + block.num_irq - 1);
}
fbl::AllocChecker ac;
auto msi = fbl::AdoptRef<MsiAllocation>(new (&ac) MsiAllocation(block, msi_free_fn));
if (!ac.check()) {
return ZX_ERR_NO_MEMORY;
}
kcounter_add(msi_create_count, 1);
cleanup.cancel();
*obj = ktl::move(msi);
return ZX_OK;
}
zx_status_t MsiAllocation::ReserveId(MsiId msi_id) {
if (msi_id >= block_.num_irq) {
return ZX_ERR_INVALID_ARGS;
}
Guard<SpinLock, IrqSave> guard{&lock_};
auto id_mask = (1u << msi_id);
if (ids_in_use_ & id_mask) {
return ZX_ERR_ALREADY_BOUND;
}
ids_in_use_ |= id_mask;
return ZX_OK;
}
zx_status_t MsiAllocation::ReleaseId(MsiId msi_id) {
if (msi_id >= block_.num_irq) {
return ZX_ERR_INVALID_ARGS;
}
Guard<SpinLock, IrqSave> guard{&lock_};
auto id_mask = (1u << msi_id);
if (!(ids_in_use_ & id_mask)) {
return ZX_ERR_BAD_STATE;
}
ids_in_use_ &= ~id_mask;
return ZX_OK;
}
MsiAllocation::~MsiAllocation() {
Guard<SpinLock, IrqSave> guard{&lock_};
DEBUG_ASSERT(ids_in_use_ == 0);
msi_block_t block = block_;
if (block_.allocated) {
msi_free_fn_(&block);
}
DEBUG_ASSERT(!block.allocated);
kcounter_add(msi_destroy_count, 1);
}
void MsiAllocation::GetInfo(zx_info_msi* info) const TA_EXCL(lock_) {
DEBUG_ASSERT(info);
Guard<SpinLock, IrqSave> guard{&lock_};
info->target_addr = block_.tgt_addr;
info->target_data = block_.tgt_data;
info->base_irq_id = block_.base_irq_id;
info->interrupt_count = ktl::popcount(ids_in_use_);
info->num_irq = block_.num_irq;
}
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
a43405109cfd7c78b10c97872b1c05b6b4bd14a6 | 6c59e769ac15dd678e9377ac9b875d6655466efc | /src/particle_filter.cpp | 9a4622a3f935edcfa7341b6c25a7e664997238ad | [
"MIT"
] | permissive | mhuang005/CarND-Term2-Kidnapped-Vehicle-P3 | c4e0346632aea51b422ad2ceb06ecbb63b0c83d3 | d9b510d08d0ebfca4120796d75790caff1ec612d | refs/heads/master | 2020-03-26T06:33:08.118666 | 2018-08-13T17:14:57 | 2018-08-13T17:14:57 | 144,607,049 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,426 | cpp | /*
* particle_filter.cpp
*
*/
#include <random>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <math.h>
#include <iostream>
#include <sstream>
#include <string>
#include <iterator>
#include <limits>
#include "particle_filter.h"
using namespace std;
void ParticleFilter::init(double x, double y, double theta, double std[]) {
if (is_initialized) return;
// Number of particles used for the filter
num_particles = 10;
// Generate Gaussian (sensor) noise for x, y and theta
default_random_engine gen;
normal_distribution<double> dist_x(0, std[0]);
normal_distribution<double> dist_y(0, std[1]);
normal_distribution<double> dist_theta(0, std[2]);
for (int i = 0; i < num_particles; i++) {
// create a particle and store it in the particle array
Particle p{ i, // id
x + dist_x(gen),
y + dist_y(gen),
theta + dist_theta(gen),
1.0 // weight
};
particles.push_back(p);
weights.push_back(1.0);
}
// Done the initialization
is_initialized = true;
}
void ParticleFilter::prediction(double delta_t, double std_pos[], double velocity, double yaw_rate) {
// Generate Gaussian (sensor) noise for x, y and theta
default_random_engine gen;
normal_distribution<double> dist_x(0, std_pos[0]);
normal_distribution<double> dist_y(0, std_pos[1]);
normal_distribution<double> dist_theta(0, std_pos[2]);
for (auto& p: particles) {
// Predicte x, y and theta based on motion model
if (fabs(yaw_rate) > 1e-5) { // Avoid division by 0
p.x += velocity/yaw_rate * (sin(p.theta + yaw_rate*delta_t) - sin(p.theta));
p.y += velocity/yaw_rate * (cos(p.theta) - cos(p.theta + yaw_rate*delta_t));
p.theta += yaw_rate * delta_t;
}
else {
p.x += velocity * delta_t * cos(p.theta);
p.y += velocity * delta_t * sin(p.theta);
}
// Add sensor noise
p.x += dist_x(gen);
p.y += dist_y(gen);
p.theta += dist_theta(gen);
}
}
void ParticleFilter::dataAssociation(std::vector<LandmarkObs> predicted, std::vector<LandmarkObs>& observations) {
// For each observation/landmark, search the nearest predicted measurement
// and assign its id to the observation's id
for (auto& obs: observations) {
double min_dist = numeric_limits<double>::infinity();
for (auto& pred: predicted) {
double dist = (obs.x-pred.x)*(obs.x-pred.x) + (obs.y-pred.y)*(obs.y-pred.y);
if (min_dist > dist) {
obs.id = pred.id;
min_dist = dist;
}
}
}
}
void ParticleFilter::updateWeights(double sensor_range, double std_landmark[],
const std::vector<LandmarkObs> &observations, const Map &map_landmarks) {
// NOTE: The observations are given in the VEHICLE'S coordinate system. Your particles are located
// according to the MAP'S coordinate system. You will need to transform between the two systems.
// Keep in mind that this transformation requires both rotation AND translation (but no scaling).
// The following is a good resource for the theory:
// https://www.willamette.edu/~gorr/classes/GeneralGraphics/Transforms/transforms2d.htm
// and the following is a good resource for the actual equation to implement (look at equation
// 3.33
// http://planning.cs.uiuc.edu/node99.
int idx = 0; // Track the particle's index in the vector
double dist = sensor_range * sensor_range;
double std_x = std_landmark[0];
double std_y = std_landmark[1];
double var_x = std_x * std_x;
double var_y = std_y * std_y;
double normalizer = 0.5 / (M_PI * std_x * std_y);
for (auto& p: particles) {
// Transform observations from (local) car/particle coordinates to (global) map coordinates
vector<LandmarkObs> obs_meas;
for (const auto& obs: observations) {
double x_map = p.x + obs.x * cos(p.theta) - obs.y * sin(p.theta);
double y_map = p.y + obs.x * sin(p.theta) + obs.y * cos(p.theta);
obs_meas.push_back(LandmarkObs{-1, x_map, y_map});
}
// Choose the landmarks in a range
vector<LandmarkObs> pred_meas;
for (const auto& landmark: map_landmarks.landmark_list) {
double diff_x = p.x - landmark.x_f;
double diff_y = p.y - landmark.y_f;
if (diff_x*diff_x + diff_y*diff_y < dist) {
pred_meas.push_back(LandmarkObs{landmark.id_i, landmark.x_f, landmark.y_f});
}
}
dataAssociation(pred_meas, obs_meas);
// Calculate the particle's weight
p.weight = 1.0;
for (const auto& obs: obs_meas) {
for (const auto& pred: pred_meas) {
if (obs.id == pred.id) {
double diff_x = pred.x - obs.x;
double diff_y = pred.y - obs.y;
double prob = normalizer * exp(-0.5*diff_x*diff_x/var_x - 0.5*diff_y*diff_y/var_y);
if (prob == 0) prob = 1e-6;
p.weight *= prob;
break;
}
}
}
weights[idx] = p.weight;
idx++;
}
}
void ParticleFilter::resample() {
// Implement the resampling wheel algorithm
default_random_engine gen;
uniform_int_distribution<int> dist_i(0, num_particles-1);
int idx = dist_i(gen);
double beta = 0;
double max_w = *max_element(weights.begin(), weights.end());
uniform_real_distribution<double> dist_r(0, max_w);
vector<Particle> resampled_particles;
for (int i = 0; i < num_particles; i++) {
beta += 2.0 * dist_r(gen);
while (beta > weights[idx]) {
beta -= weights[idx];
idx = (idx + 1) % num_particles;
}
resampled_particles.push_back(particles[idx]);
}
particles = resampled_particles;
}
Particle ParticleFilter::SetAssociations(Particle& particle, const std::vector<int>& associations,
const std::vector<double>& sense_x, const std::vector<double>& sense_y)
{
//particle: the particle to assign each listed association, and association's (x,y) world coordinates mapping to
// associations: The landmark id that goes along with each listed association
// sense_x: the associations x mapping already converted to world coordinates
// sense_y: the associations y mapping already converted to world coordinates
particle.associations.clear();
particle.sense_x.clear();
particle.sense_y.clear();
particle.associations= associations;
particle.sense_x = sense_x;
particle.sense_y = sense_y;
return particle;
}
string ParticleFilter::getAssociations(Particle best)
{
vector<int> v = best.associations;
stringstream ss;
copy( v.begin(), v.end(), ostream_iterator<int>(ss, " "));
string s = ss.str();
s = s.substr(0, s.length()-1); // get rid of the trailing space
return s;
}
string ParticleFilter::getSenseX(Particle best)
{
vector<double> v = best.sense_x;
stringstream ss;
copy( v.begin(), v.end(), ostream_iterator<float>(ss, " "));
string s = ss.str();
s = s.substr(0, s.length()-1); // get rid of the trailing space
return s;
}
string ParticleFilter::getSenseY(Particle best)
{
vector<double> v = best.sense_y;
stringstream ss;
copy( v.begin(), v.end(), ostream_iterator<float>(ss, " "));
string s = ss.str();
s = s.substr(0, s.length()-1); // get rid of the trailing space
return s;
}
| [
"huang3@mc18.cs.purdue.edu"
] | huang3@mc18.cs.purdue.edu |
4f1e6703e0f6d2478e7eecf5203cf583ce9e0d66 | d1da19b3e6554322c7b2a25eb61a29ad85a6a12b | /include/quaternion_angle_cost_function.h | 8883bc7fe6a1411eb91f448b603bc3707ae155ac | [] | no_license | apalomer/spatial_relationships | c9093cc3d29cbd70fc1283d3bca7cb2d3743dac7 | afb6eddec77f06797d0690797e4c5a9a402f2588 | refs/heads/master | 2020-03-09T13:04:51.635943 | 2018-10-11T13:02:24 | 2018-10-11T13:02:24 | 128,801,404 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,472 | h | #ifndef QUATERNION_ANGLE_COST_FUNCTION_H
#define QUATERNION_ANGLE_COST_FUNCTION_H
#include <ceres/ceres.h>
#include "transformations.h"
#include "functions.h"
/*!
* \brief The QuaternionAngle cost function class
* \callgraph
* \callergraph
*/
class QuaternionAngle: public ceres::SizedCostFunction<1,4,4>
{
public:
/*!
* \brief Constructor
*/
QuaternionAngle();
~QuaternionAngle();
/*!
* \brief Evaluate the cost function with the given parameters
* \param parameters
* \param[out] residuals
* \param[out] jacobians
* \return ture/false if the residuals and the jacobians have been properly evaluated.
* \callgraph
* \callergraph
*/
bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const;
/*!
* \brief operator() evaluates the cost function for the given parameters.
* \param q1
* \param q2
* \param[out] residuals = quaternionAngle(q1,q2)
* \return ture/false if the residuals and the jacobians have been properly evaluated.
* \callgraph
* \callergraph
*/
template<typename T>
bool operator()(const T* const q1, const T* const q2, T* residuals) const
{
Eigen::Quaternion<T> q_1(q1[0],q1[1],q1[2],q1[3]);
Eigen::Quaternion<T> q_2(q2[0],q2[1],q2[2],q2[3]);
residuals[0] = quaternionAngle<T>(q_1,q_2);
return true;
}
};
#endif // QUATERNION_ANGLE_COST_FUNCTION_H
| [
"albert.palo@gmail.com"
] | albert.palo@gmail.com |
6f38aaccea85a51420e4b6ec01b4e6891ba78cd6 | 215111e92a3dfc535ce1c1ce25a35fb6003ab575 | /cf/cf_global7/a.cpp | 30ecc42d25b0dde7983a9d678d6a44c71f77856e | [] | no_license | emanueljuliano/Competitive_Programming | 6e65aa696fb2bb0e2251e5a68657f4c79cd8f803 | 86fefe4d0e3ee09b5766acddc8c78ed8b60402d6 | refs/heads/master | 2023-06-23T04:52:43.910062 | 2021-06-26T11:34:42 | 2021-06-26T11:34:42 | 299,115,304 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 592 | cpp | #include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
int main(){ _
int t; cin >> t;
while(t--){
int n; cin >> n;
if(n==1) {cout << -1 << endl; continue;}
if(n%3!=1){
for(int i=0; i<n-1; i++){
cout << 2;
}
cout << 3 << endl;
}
else{
for(int i=0; i<n-2; i++){
cout << 2;
}
cout << 33 << endl;
}
}
exit(0);
}
| [
"emanueljulianoms@gmail.com"
] | emanueljulianoms@gmail.com |
045071544712ef77ba20c6e8b977fa910a0404df | afa52b0c6cb73c634b54aa1445ec238e567356ad | /project1/RegistrationServer.cpp | 54373170e2011c7f5547473448a5ae82e53eae20 | [] | no_license | lbadams2/csc573 | f3f3ac4f5edb638fde131fc8cf245eaf075bbbca | d9d4f310d277a269b3288e7fdbcb8cbf4f057467 | refs/heads/master | 2020-05-29T13:03:59.724773 | 2019-07-04T19:23:35 | 2019-07-04T19:23:35 | 189,147,945 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,880 | cpp | #include "RegistrationServer.h"
RegistrationServer::RegistrationServer(): peer_list(std::vector<PeerDetails>()) {
char hostname[1024];
hostname[1023] = '\0';
gethostname(hostname, 1023);
std::string s(hostname);
host_name = s;
}
std::string const RegistrationServer::response_str = "P2P-DI/1.0 <status_code> <phrase> \r\nContent-Length: <LENGTH>\r\nCOOKIE: <COOKIE>\r\nDATE: <DATE>\r\nPORT: <PORT>\r\nHOST: <HOST>\r\n";
void RegistrationServer::run_thread() {
th = std::thread(&RegistrationServer::start_server, this);
//th.join();
}
void RegistrationServer::start_server() {
int server_fd, new_socket, client_socket[30], max_clients = 30;
int opt = 1, max_sd, i, sd;
struct sockaddr_in address;
int addrlen = sizeof(address);
char buffer[1024] = {0};
// set of socket descriptors
fd_set readfds;
for (i = 0; i < max_clients; i++) {
client_socket[i] = 0;
}
if((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
perror("socket failed");
exit(EXIT_FAILURE);
}
// set socket to accept multiple connections
if(setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
perror("rs setsockopt");
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
// bind socket to port
if(bind(server_fd, (struct sockaddr *) &address, sizeof(address)) < 0) {
perror("bind failed");
exit(EXIT_FAILURE);
}
// 3 is how many pending connections queue will hold
if(listen(server_fd, 300) < 0) {
perror("listen");
exit(EXIT_FAILURE);
}
while(true) {
// clear the socket set
FD_ZERO(&readfds);
// add listen socket to set
FD_SET(server_fd, &readfds);
max_sd = server_fd;
for(i = 0; i < max_clients; i++) {
sd = client_socket[i];
if(sd > 0)
FD_SET(sd, &readfds);
if(sd > max_sd)
max_sd = sd;
}
select(max_sd + 1, &readfds, NULL, NULL, NULL);
// if something happened on server_fd (socket), then its an incoming connection
if(FD_ISSET(server_fd, &readfds)) {
if((new_socket = accept(server_fd, (struct sockaddr *) &address, (socklen_t*) &addrlen)) < 0) {
perror("accept");
exit(EXIT_FAILURE);
}
//printf("New connection , socket fd is %d , ip is : %s , port : %d \n" , new_socket , inet_ntoa(address.sin_addr) , ntohs
// (address.sin_port));
int length = 1024;
bzero(buffer, length);
int block_sz = 0;
std::string req = "";
while((block_sz = read(new_socket, buffer, 1024)) > 0) {
std::string chunk(buffer);
req += chunk;
bzero(buffer, length);
if(block_sz == 0 || block_sz != length)
break;
}
std::cout << "Registration server incoming request\n" << req << "\n";
std::unordered_map<std::string, std::string> req_map = read_request(req);
std::string response_str;
if(req_map["type"] == "REGISTER")
response_str = register_peer(req_map);
else if(req_map["type"] == "STOP") {
response_str = get_stop_response(req_map);
const char* c_res_str = response_str.c_str();
send(new_socket, c_res_str, strlen(c_res_str), 0);
break;
}
else if(req_map["type"] == "PQUERY")
response_str = pquery(req_map);
else if(req_map["type"] == "LEAVE")
response_str = leave(req_map);
else if(req_map["type"] == "KEEPALIVE")
response_str = keep_alive(req_map);
const char* c_res_str = response_str.c_str();
send(new_socket, c_res_str, strlen(c_res_str), 0);
}
}
close(server_fd);
return;
}
std::string PeerDetails::to_string() const {
std::string str = "host:" + host_name + " port:" + std::to_string(port) + " peer_name:" + peer_name;
return str;
}
std::string RegistrationServer::leave(std::unordered_map<std::string, std::string> &request) {
std::string name = request["PEER_NAME"];
trim(name);
auto it = find_if(peer_list.begin(), peer_list.end(), [&name](const PeerDetails& p){return p.peer_name == name;});
(*it).is_active = false;
std::string res = get_response_string(200, "LEFT", *it);
return res;
}
std::string RegistrationServer::keep_alive(std::unordered_map<std::string, std::string> &request) {
std::string name = request["PEER_NAME"];
trim(name);
auto it = find_if(peer_list.begin(), peer_list.end(), [&name](const PeerDetails& p){return p.peer_name == name;});
(*it).is_active = true;
(*it).registration_time = time(0);
std::string res = get_response_string(200, "ALIVE", *it);
return res;
}
std::string RegistrationServer::pquery(std::unordered_map<std::string, std::string> &request) {
std::string name = request["PEER_NAME"];
trim(name);
time_t now = time(0);
auto it = find_if(peer_list.begin(), peer_list.end(), [&name](const PeerDetails& p){return p.peer_name == name;});
std::string res = get_response_string(200, "OK", *it);
std::string data;
for(auto pd: peer_list) {
if(pd.is_active) {
if(now - pd.registration_time < 7200 && pd.peer_name != name)
data += pd.to_string() + "\r\n";
else
pd.is_active = false;
}
}
if(data.length() > 0)
res += data + "\r\n";
else {
data = "No active peers\r\n";
res += data;
}
replace(res, "Content-Length: 0", "Content-Length: " + std::to_string(data.size()));
return res;
}
std::string RegistrationServer::register_peer(std::unordered_map<std::string, std::string> &request) {
time_t now = time(0);
char* dt = ctime(&now);
std::string date_string(dt);
trim(date_string);
std::string thehost = request["HOST"];
trim(thehost);
std::string name = request["PEER_NAME"];
trim(name);
int port_num = stoi(request["PEER_SERVER_PORT"]);
auto it = find_if(peer_list.begin(), peer_list.end(), [&name](const PeerDetails& p){return p.peer_name == name;});
if(it != peer_list.end()) {
PeerDetails pd = *it;
pd.is_active = true;
pd.ttl = 7200;
pd.times_registered++;
pd.datetime = date_string;
pd.port = port_num;
pd.registration_time = now;
return get_response_string(200, "UPDATED", pd);
} else {
PeerDetails pd = PeerDetails();
pd.host_name = thehost;
pd.peer_name = name;
pd.is_active = true;
pd.ttl = 7200;
pd.times_registered = 1;
pd.datetime = date_string;
pd.cookie = peer_list.size();
pd.port = port_num;
pd.registration_time = now;
peer_list.push_back(pd);
return get_response_string(204, "CREATED", pd);
}
}
bool RegistrationServer::replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
std::string RegistrationServer::get_stop_response(std::unordered_map<std::string, std::string> &request) {
std::string s = response_str;
std::string name = request["PEER_NAME"];
trim(name);
auto it = find_if(peer_list.begin(), peer_list.end(), [&name](const PeerDetails& p){return p.peer_name == name;});
PeerDetails pd = *it;
return get_response_string(209, "STOPPED", pd);
}
std::string RegistrationServer::get_response_string(int code, std::string phrase, PeerDetails &pd) {
std::string s = response_str;
replace(s, "<status_code>", std::to_string(code));
replace(s, "<phrase>", phrase);
replace(s, "<HOST>", host_name);
replace(s, "<PORT>", std::to_string(PORT));
replace(s, "<COOKIE>", std::to_string(pd.cookie));
replace(s, "<DATE>", pd.datetime);
replace(s, "<LENGTH>", "0");
s += "\r\n";
return s;
}
std::unordered_map<std::string, std::string> RegistrationServer::read_request(std::string &req) {
std::unordered_map<std::string, std::string> map;
std::string::size_type pos = 0, prev = 0;
std::string delimiter = "\r\n", type = "", method = "", val = "", key = "", data = "";
int line_num = 0;
while((pos = req.find(delimiter, prev)) != std::string::npos) {
std::string line = req.substr(prev, pos-prev);
//std::cout << "rs str to map " << line << "\n";
if(line.length() == 0)
break;
if(line_num == 0) {
method = line.substr(0, 1);
if(method == "P") {
map["method"] = "POST";
type = line.substr(5, 1);
}
else {
map["method"] = "GET";
type = line.substr(4, 1);
}
if(type == "R")
map["type"] = "REGISTER";
else if(type == "L")
map["type"] = "LEAVE";
else if(type == "P")
map["type"] = "PQUERY";
else if(type == "K")
map["type"] = "KEEPALIVE";
else if(type == "S")
map["type"] = "STOP";
line_num++;
prev = pos + delimiter.size();
continue;
}
key = line.substr(0, line.find(":"));
val = line.substr(line.find(":") + 1);
map[key] = val;
prev = pos + delimiter.size();
}
return map;
}
| [
"lbadams2@ncsu.edu"
] | lbadams2@ncsu.edu |
d1960e66222b17ff20a02fd4db1b8a91f03deb54 | 81d61a0e4081c85076663622b14d7d71d7665d87 | /src/clients/HeartbeatTimerTask.h | 482f6ac3b0eee2442ed062a6c1209c161c8e90e6 | [
"Apache-2.0"
] | permissive | cakapilrana/pushfyi | 22dabcfbad579deef7a5847ee28b789971d93940 | 7ec8461b73e19b72c8eda38b337737c010b79885 | refs/heads/master | 2020-03-14T02:04:49.988696 | 2018-05-31T11:46:03 | 2018-05-31T11:46:03 | 131,391,720 | 8 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,558 | h | /*
* HeartbeatTimerTask.h
*
* Created on: 24-Apr-2017
* Author: vikas
*/
#ifndef HEARTBEATTIMERTASK_H_
#define HEARTBEATTIMERTASK_H_
#include <string>
#include "Event.h"
#include "TimerCb.h"
class PushFYIClient;
class HeartbeatTimerTaskRep
: public TimerCbRep
{
public:
HeartbeatTimerTaskRep();
HeartbeatTimerTaskRep(PushFYIClient* client, const timeval* expiryTime);
HeartbeatTimerTaskRep(HeartbeatTimerTaskRep& toCopy);
virtual ~HeartbeatTimerTaskRep();
virtual void process(timeval* tv);
private:
PushFYIClient* mClient;
};
class HeartbeatTimerTask
: public TimerCb
{
public:
HeartbeatTimerTask();
HeartbeatTimerTask(HeartbeatTimerTaskRep* rep);
HeartbeatTimerTask(const HeartbeatTimerTask& toCopy);
virtual ~HeartbeatTimerTask();
HeartbeatTimerTask& operator=(const HeartbeatTimerTask& toCopy);
bool operator==(const HeartbeatTimerTask& toCompare);
HeartbeatTimerTaskRep* operator->() const;
HeartbeatTimerTaskRep* operator*() const;
private:
};
inline HeartbeatTimerTask& HeartbeatTimerTask::operator=(const HeartbeatTimerTask& toCopy)
{
return (HeartbeatTimerTask&) Ref::operator=(toCopy);
}
inline bool HeartbeatTimerTask::operator==(const HeartbeatTimerTask& toCompare)
{
return mRep == toCompare.mRep;
}
inline HeartbeatTimerTaskRep* HeartbeatTimerTask::operator->() const
{
return (HeartbeatTimerTaskRep*) mRep;
}
inline HeartbeatTimerTaskRep* HeartbeatTimerTask::operator*() const
{
return (HeartbeatTimerTaskRep*) mRep;
}
#endif /* HEARTBEATTIMERTASK_H_ */
| [
"cakapilrana@gmail.com"
] | cakapilrana@gmail.com |
c9bbfd5bf967b0049cbe0e945be940ad56fa80e9 | 188dba2c21fa5e607efd9f0453b128b5773c616c | /Days 161 - 170/Day 169/SortLinkedList.cpp | 59c633264d36f6d5edf7b9b11e87b498d8bf029d | [
"MIT"
] | permissive | LucidSigma/Daily-Coding-Problems | 0f8c460817301baa9f1744a8f2b3f5658ba7a8c7 | 21dc8f7e615edd535d7beb1f5d0e41dd3b4bcc1a | refs/heads/master | 2020-04-08T17:43:22.269849 | 2019-11-28T00:49:20 | 2019-11-28T00:49:20 | 159,578,664 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,877 | cpp | #include <iostream>
#include <memory>
#include <vector>
struct Node
{
int value;
std::shared_ptr<Node> next;
explicit Node(const int value, const std::shared_ptr<Node>& next = nullptr) noexcept
: value{ value }, next{ next }
{ }
};
std::shared_ptr<Node> MergeSortedLinkedLists(const std::shared_ptr<Node>& listA, const std::shared_ptr<Node>& listB) noexcept
{
std::shared_ptr<Node> head{ std::make_shared<Node>(std::numeric_limits<int>::min()) };
std::shared_ptr<Node> currentNode{ head };
std::shared_ptr<Node> nodeA{ listA };
std::shared_ptr<Node> nodeB{ listB };
while (nodeA != nullptr && nodeB != nullptr)
{
std::shared_ptr<Node> tempNode{ nodeA->value < nodeB->value ? nodeA : nodeB };
if (nodeA->value < nodeB->value)
{
nodeA = nodeA->next;
}
else
{
nodeB = nodeB->next;
}
tempNode->next = nullptr;
currentNode->next = tempNode;
currentNode = currentNode->next;
}
if (nodeA != nullptr)
{
currentNode->next = nodeA;
}
if (nodeB != nullptr)
{
currentNode->next = nodeB;
}
return head->next;
}
std::shared_ptr<Node> SortLinkedListHelper(const std::shared_ptr<Node>& linkedList, const unsigned int nodeCount) noexcept
{
if (nodeCount == 1)
{
return linkedList;
}
const unsigned int midPoint = nodeCount / 2;
std::shared_ptr<Node> rightListHead{ linkedList };
std::shared_ptr<Node> leftListTail{ nullptr };
for (unsigned int i{ 0 }; i < midPoint; ++i)
{
leftListTail = rightListHead;
rightListHead = rightListHead->next;
}
leftListTail->next = nullptr;
const std::shared_ptr<Node> sortedLeftList{ SortLinkedListHelper(linkedList, midPoint) };
const std::shared_ptr<Node> sortedRightList{ SortLinkedListHelper(rightListHead, nodeCount - midPoint) };
return MergeSortedLinkedLists(sortedLeftList, sortedRightList);
}
std::shared_ptr<Node> SortLinkedList(const std::shared_ptr<Node>& linkedList) noexcept
{
unsigned int nodeCount{ 0 };
auto currentNode{ linkedList };
while (currentNode != nullptr)
{
++nodeCount;
currentNode = currentNode->next;
}
return SortLinkedListHelper(linkedList, nodeCount);
}
std::ostream& operator <<(std::ostream& outputStream, const std::shared_ptr<Node>& linkedList) noexcept
{
auto currentNode{ linkedList };
outputStream << "[ ";
while (currentNode != nullptr)
{
outputStream << currentNode->value << " ";
currentNode = currentNode->next;
}
outputStream << "]";
return outputStream;
}
int main(int argc, char* argv[])
{
const auto node99{ std::make_shared<Node>(99) };
const auto nodeN3{ std::make_shared<Node>(-3, node99) };
const auto node1{ std::make_shared<Node>(1, nodeN3) };
const auto node4{ std::make_shared<Node>(4, node1) };
std::cout << "Before sorting: " << node4 << "\n";
const auto sortedList{ SortLinkedList(node4) };
std::cout << " After sorting: " << sortedList << "\n";
std::cin.get();
return 0;
} | [
"lucidsigma17@gmail.com"
] | lucidsigma17@gmail.com |
ece67661a6c3387ad112e9adce0cd326e2d71cad | 0aa9c225410ece898d1ff2cbe94a5bb10f3de9c6 | /open_chisel/include/open_chisel/marching_cubes/MarchingCubes.h | 3d711f96f0c55d566d50f7c49262b23b082a0380 | [
"MIT"
] | permissive | shenglixu/OpenChisel | 62cb90c317670b3694a4743142d83925297b075e | f0fb522772c2281a61cc78ae3e8f1f8e6701683d | refs/heads/master | 2021-05-30T10:15:00.646151 | 2014-11-06T16:44:41 | 2014-11-06T16:44:41 | 31,393,098 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,650 | h | // The MIT License (MIT)
// Copyright (c) 2014 Matthew Klingensmith and Ivan Dryanovski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef MARCHINGCUBES_H_
#define MARCHINGCUBES_H_
#include <open_chisel/geometry/Geometry.h>
#include <open_chisel/mesh/Mesh.h>
namespace chisel
{
typedef std::vector<Mat3x3, Eigen::aligned_allocator<Mat3x3> > TriangleVector;
class MarchingCubes
{
public:
static int triangleTable[256][16];
static int edgeIndexPairs[12][2];
MarchingCubes();
virtual ~MarchingCubes();
static void MeshCube(const Eigen::Matrix<float, 3, 8>& vertex_coordinates, const Eigen::Matrix<float, 8, 1>& vertexSDF, TriangleVector* triangles)
{
assert(triangles != nullptr);
const int index = CalculateVertexConfiguration(vertexSDF);
Eigen::Matrix<float, 3, 12> edgeCoords;
InterpolateEdgeVertices(vertex_coordinates, vertexSDF, &edgeCoords);
const int* table_row = triangleTable[index];
int edgeIDX = 0;
int tableCol = 0;
while ((edgeIDX = table_row[tableCol]) != -1)
{
Eigen::Matrix3f triangle;
triangle.col(0) = edgeCoords.col(edgeIDX);
edgeIDX = table_row[tableCol + 1];
triangle.col(1) = edgeCoords.col(edgeIDX);
edgeIDX = table_row[tableCol + 2];
triangle.col(2) = edgeCoords.col(edgeIDX);
triangles->push_back(triangle);
tableCol += 3;
}
}
static void MeshCube(const Eigen::Matrix<float, 3, 8>& vertexCoords, const Eigen::Matrix<float, 8, 1>& vertexSDF, VertIndex* nextIDX, Mesh* mesh)
{
assert(nextIDX != nullptr);
assert(mesh != nullptr);
const int index = CalculateVertexConfiguration(vertexSDF);
Eigen::Matrix<float, 3, 12> edge_vertex_coordinates;
InterpolateEdgeVertices(vertexCoords, vertexSDF, &edge_vertex_coordinates);
const int* table_row = triangleTable[index];
int table_col = 0;
while (table_row[table_col] != -1)
{
mesh->vertices.emplace_back(edge_vertex_coordinates.col(table_row[table_col + 2]));
mesh->vertices.emplace_back(edge_vertex_coordinates.col(table_row[table_col + 1]));
mesh->vertices.emplace_back(edge_vertex_coordinates.col(table_row[table_col]));
mesh->indices.push_back(*nextIDX);
mesh->indices.push_back((*nextIDX) + 1);
mesh->indices.push_back((*nextIDX) + 2);
const Eigen::Vector3f& p0 = mesh->vertices[*nextIDX];
const Eigen::Vector3f& p1 = mesh->vertices[*nextIDX + 1];
const Eigen::Vector3f& p2 = mesh->vertices[*nextIDX + 2];
Eigen::Vector3f px = (p1 - p0);
Eigen::Vector3f py = (p2 - p0);
Eigen::Vector3f n = px.cross(py).normalized();
mesh->normals.push_back(n);
mesh->normals.push_back(n);
mesh->normals.push_back(n);
*nextIDX += 3;
table_col += 3;
}
}
static int CalculateVertexConfiguration(const Eigen::Matrix<float, 8, 1>& vertexSDF)
{
return (vertexSDF(0) < 0 ? (1<<0) : 0) |
(vertexSDF(1) < 0 ? (1<<1) : 0) |
(vertexSDF(2) < 0 ? (1<<2) : 0) |
(vertexSDF(3) < 0 ? (1<<3) : 0) |
(vertexSDF(4) < 0 ? (1<<4) : 0) |
(vertexSDF(5) < 0 ? (1<<5) : 0) |
(vertexSDF(6) < 0 ? (1<<6) : 0) |
(vertexSDF(7) < 0 ? (1<<7) : 0);
}
static void InterpolateEdgeVertices(const Eigen::Matrix<float, 3, 8>& vertexCoords, const Eigen::Matrix<float, 8, 1>& vertSDF, Eigen::Matrix<float, 3, 12>* edgeCoords)
{
assert(edgeCoords != nullptr);
for (std::size_t i = 0; i < 12; ++i)
{
const int* pairs = edgeIndexPairs[i];
const int edge0 = pairs[0];
const int edge1 = pairs[1];
// Only interpolate along edges where there is a zero crossing.
if ((vertSDF(edge0) < 0 && vertSDF(edge1) >= 0) || (vertSDF(edge0) >= 0 && vertSDF(edge1) < 0))
edgeCoords->col(i) = InterpolateVertex(vertexCoords.col(edge0), vertexCoords.col(edge1), vertSDF(edge0), vertSDF(edge1));
}
}
// Performs linear interpolation on two cube corners to find the approximate
// zero crossing (surface) value.
static inline Vec3 InterpolateVertex(const Vec3& vertex1, const Vec3& vertex2, const float& sdf1, const float& sdf2)
{
const float minDiff = 1e-6;
const float sdfDiff = sdf2 - sdf1;
if (std::abs(sdfDiff) < minDiff)
{
return Vec3(vertex1 + 0.5 * vertex2);
}
const float t = -sdf1 / sdfDiff;
return Vec3(vertex1 + t * (vertex2 - vertex1));
}
};
} // namespace chisel
#endif // MARCHINGCUBES_H_
| [
"mklingen@ash.personalrobotics.ri.cmu.edu"
] | mklingen@ash.personalrobotics.ri.cmu.edu |
0503dbde6820e5268f6338631210c02d8b7ef5a0 | a93dd750177e29b869167b0f19ea00ef9018375b | /selfDrivingND/ParticleFilter/src/Particle.cpp | a5c51f4fd3b182fc523d452d6c5ac6d2518c4a35 | [] | no_license | abhay1208/abhay-personal | 8721416559bb82c9d338f9e8c1406a0fa8b109dd | cee3007cd9617b96ff4d2a4472de7a43d0f87451 | refs/heads/master | 2021-01-19T15:38:57.275437 | 2020-11-13T02:09:36 | 2020-11-13T02:09:36 | 88,226,066 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,819 | cpp | #include "Particle.h"
/**
* Motion model to update particle position
* @param dT Time Delta
* @param std_pos vector of std dev in (x, y, theta)
* @param velocity - constant velocity for dT
* @param yaw_rate - constant yaw rate for dT
*/
void Particle::updatePosition(double dT, double std_pos[], double velocity, double yaw_rate)
{
if (abs(yaw_rate) < 1e-5)
{
x += velocity * dT * cos(theta);
y += velocity * dT * sin(theta);
}
else
{
x += (velocity / yaw_rate) * (sin(theta + yaw_rate * dT) - sin(theta));
y += (velocity / yaw_rate) * (cos(theta) - cos(theta + yaw_rate * dT));
theta += yaw_rate * dT;
}
// Adding noise to prediction
x = getGaussianSample(x, std_pos[0]);
y = getGaussianSample(y, std_pos[1]);
theta = getGaussianSample(theta, std_pos[2]);
}
/** Print Particle Informaton
*/
void Particle::printParticle() const
{
std::cout << "ID : " << id << "\t"
<< "X: " << x << "\t"
<< "Y: " << y << "\t"
<< "Theta: " << theta << "\t"
<< "Weight: " << weight << std::endl;
}
/**
* Assumed a multivariate gaussian distribution and return probability of (x,y) given mean and std dev of the distrbution
*/
double Particle::pdfMultVar(double mu_x, double mu_y, double sig_x, double sig_y, double x_obs, double y_obs)
{
// calculate normalization term
double gauss_norm;
gauss_norm = 1 / (2 * M_PI * sig_x * sig_y);
// // calculate exponent
double exponent;
exponent = (pow(x_obs - mu_x, 2) / (2 * pow(sig_x, 2))) + (pow(y_obs - mu_y, 2) / (2 * pow(sig_y, 2)));
// calculate weight using normalization terms and exponent
double weight;
weight = gauss_norm * exp(-exponent);
return weight;
} | [
"agupta@Abhays-MacBook-Air.local"
] | agupta@Abhays-MacBook-Air.local |
1176799c26c0bdafd4b09a5b6ebb79254145b609 | b67bcb6d907c4ce2e8207f52f08833c8a92604a6 | /main.cpp | aa1a7739380d2189504266342e5a8c21cbf1540e | [] | no_license | sajalkumar/CPTree | 10377e278e9c5a87bbc24bed66bcccc379c88a65 | 3883d3a9370ea75c568fc5ef7055aa4628c0f017 | refs/heads/master | 2021-01-12T08:00:07.472018 | 2016-12-21T19:12:51 | 2016-12-21T19:12:51 | 77,079,181 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,445 | cpp | //
// main.cpp
// CPTree
//
// Created by Sajal Kumar on 2/24/16.
// Copyright © 2016 NMSUSongLab. All rights reserved.
//
/****************************************************
* PARAMETERS FOR CPTREE *
* -k "Name of the dataset" *
* -i "Arity" *
* -m "Method" *
* -a "Alpha value" *
* -c "Correlation Test" *
* -f "fast enabled" *
* -h "Help" *
*****************************************************/
#include <iostream>
#include <string>
#include "CPTreeMain.hpp"
#include "CPChisq.h"
#include "method.hpp"
#include "CorrelationTest.hpp"
#include <fstream>
using namespace std;
int main(int argc, char* argv[]) {
string root="/Users/sajalkumar/Dropbox/";
string k="",method="",param, mode="classification";
int arity=0;
double alpha=0.00;
if(argc==1)
{
cout<<"No parameters : Running the default dataset XOR, with cpx2 method, alpha = 0.05 and arity=2"<<endl;
k="XOR";
method="funchisq";
arity=2;
alpha=0.5;
} else if(argc==2)
{
param=argv[1];
if(param.substr(0,2)=="-h"){
cout<<"Help Instructions"<<endl;
cout<<"-k Name_of_dataset"<<endl;
cout<<"-i Arity (1 or 2)"<<endl;
cout<<"-m Method (gini, cpx2, chisq, entropy, funchisqnorm or funchisq)"<<endl;
cout<<"-a Alpha value (pvalue cut off)"<<endl;
cout<<"-c Correlation Test (For dimensionality reduction, to be used singularly"<<endl;
cout<<"-f Fast enabled, a faster implementation"<<endl;
cout<<"Example .CPtree -kXOR -i2 -mcpx2"<<endl;
return 0;
} else
{
cout<<"Insufficient parameters : Running the default dataset XOR, with cpx2 method, alpha = 0.05 and arity=2"<<endl;
k="XOR";
method="cpx2";
arity=2;
alpha=0.05;
}
} else if(argc==3) {
param=argv[1];
if(param.substr(0,2)=="-c"){
mode="correlation";
param=argv[2];
k=param.substr(2);
} else {
cout<<"Insufficient parameters : Running the default dataset XOR, with cpx2 method, alpha = 0.05 and arity=2"<<endl;
k="XOR";
method="cpx2";
arity=2;
alpha=0.05;
}
}
else if(argc==5){
for(int i=1;i<argc;i++)
{
param=argv[i];
if(param.substr(0,2)=="-k")
k=param.substr(2);
if(param.substr(0,2)=="-i")
arity=stoi(param.substr(2));
if(param.substr(0,2)=="-m")
method=param.substr(2);
if(param.substr(0,2)=="-a")
alpha=stod(param.substr(2));
}
} else
{
cout<<"Invalid number of parameters : Running the default dataset XOR, with cpx2 method, alpha = 0.05 and arity=2"<<endl;
k="XOR";
method="cpx2";
arity=2;
alpha=0.05;
}
if(mode=="correlation")
{
string path=root+"CPTree/Data/NaturalData/"+k+"_natural.txt";
vecstr all=readall(path);
framestr tab=readTable(all,',');
tab=Transposeframe(tab);
tab=deleteOP<vector<string>>(tab, (int)(tab.size()-1));
vecint res=corTestMain(tab);
ofstream indexfile;
indexfile.open (root+"CPTree/Data/CorrelationIndex/"+k+"_CDeleteindex.txt");
if(res.size()==0)
indexfile<<"NILL";
else
{
for(int i=0;i<res.size();i++)
indexfile<<to_string(res[i])+"\t";
}
indexfile<<"\n";
indexfile.close();
cout<<"Correlation Test Done!!"<<endl<<"Results in "<<root<<"Data/CorrelationIndex/"<<endl;
return 0;
}
// vecdouble x,y,z;
// for(int i=0;i<10;i++)
// {
// x.push_back(30-i);
// y.push_back(50-i);
// z.push_back(100-i);
// }
// framedouble all;
// all.push_back(x);
// all.push_back(y);
// all.push_back(z);
//
// printframe(all);
//
// framedouble res=sortFrame(all, 1,"ascending");
//
// printframe(res);
string path=root+"CPTree/Data/ReadData/"+k+"_Categorized.txt";
vecstr all=readall(path);
framestr tab=readTable(all,',');
tab=Transposeframe(tab);
CPTree cp(tab[tab.size()-1],((int)tab.size()-1));
cp.CPTreeMainIterative(tab,method,arity,alpha);
framestr treestruct=cp.getTreeStruct();
ofstream myfile;
if(method=="gini"){
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesGini/"+k+"_Tree.txt");
} else if(method=="cpx2"){
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesCPX2/"+k+"_Tree.txt");
} else if(method=="funchisq"){
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesFunChisq/"+k+"_Tree.txt");
} else if(method=="fastfunchisq"){
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesFunChisqFast/"+k+"_Tree.txt");
} else if(method=="chisq") {
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesChisq/"+k+"_Tree.txt");
} else if(method=="entropy") {
while(!myfile.is_open())
myfile.open (root+"CPTree/Data/TreesEntropy/"+k+"_Tree.txt");
}
for(int i=0;i<treestruct.size();i++)
{
for(int j=0;j<treestruct[i].size();j++)
{
if(j<treestruct[i].size()-1)
myfile <<treestruct[i][j]+"\t";
else
myfile <<treestruct[i][j];
}
myfile<<"\n";
}
myfile.close();
vecstr colnm=cp.getColumnNames();
ofstream myfile2;
while(!myfile2.is_open())
myfile2.open (root+"CPTree/Data/Column-names/"+k+"_colnames.txt");
for(int i=0;i<colnm.size();i++)
{
if(i<colnm.size()-1)
myfile2<<colnm[i]+",";
else
myfile2<<colnm[i]+"\n";
}
myfile2.close();
cout<<"Done"<<endl<<"Results in "<<root<<"CPTree/Data/"<<endl;
return 0;
}
| [
"noreply@github.com"
] | noreply@github.com |
67454e59e295b8b932d59f6b391c1b78da9becae | 04753aa29cdaab2ab16c8e2062c732bc4d915556 | /model/bind-server.cc | c57606dea06f51d8ee67df182934c8295c7c3861 | [] | no_license | janakawest/DNS-for-NS3 | 07efcb4a2c6c86d9df92f1e74df613600719d345 | 458f40c78eea7ad3b6a283ead62a1cd39c90672f | refs/heads/master | 2020-12-25T20:43:17.729632 | 2016-03-08T07:00:56 | 2016-03-08T07:00:56 | 53,138,108 | 6 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 26,733 | cc | #include "ns3/log.h"
#include "ns3/ipv4-address.h"
#include "ns3/address-utils.h"
#include "ns3/nstime.h"
#include "ns3/inet-socket-address.h"
#include "ns3/socket.h"
#include "ns3/udp-socket.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include "ns3/enum.h"
#include "ns3/abort.h"
#include "bind-server.h"
#include "ns3/dns.h"
#include "ns3/dns-header.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE ("BindServer");
NS_OBJECT_ENSURE_REGISTERED (BindServer);
TypeId
BindServer::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::BindServer")
.SetParent <Application> ()
.AddConstructor <BindServer> ()
.AddAttribute ("SetServerAddress",
"IP address of the server.",
Ipv4AddressValue (),
MakeIpv4AddressAccessor (&BindServer::m_localAddress),
MakeIpv4AddressChecker ())
.AddAttribute ("RootServerAddress",
"Ip address of the Root Server (This is only needed for Local NS).",
Ipv4AddressValue (),
MakeIpv4AddressAccessor (&BindServer::m_rootAddress),
MakeIpv4AddressChecker ())
.AddAttribute ("SetNetMask",
"Network Mask of the server.",
Ipv4MaskValue (),
MakeIpv4MaskAccessor (&BindServer::m_netMask),
MakeIpv4MaskChecker ())
.AddAttribute ("NameServerType",
" Type of the name server.",
EnumValue (AUTH_SERVER),
MakeEnumAccessor (&BindServer::m_serverType),
MakeEnumChecker (LOCAL_SERVER, "LOCAL NAME SERVER",
ROOT_SERVER, "ROOT NAME SERVER",
TLD_SERVER, "TOP-LEVEL DOMAIN SERVER",
ISP_SERVER, "ISP'S NAME SERVER",
AUTH_SERVER, "AUTHORITATIVE NAME SERVER"))
.AddAttribute ("SetRecursiveSupport",
"Set the name server support recursive IP resolution",
EnumValue (BindServer::RA_UNAVAILABLE),
MakeEnumAccessor (&BindServer::m_raType),
MakeEnumChecker (BindServer::RA_UNAVAILABLE, "Does not support",
BindServer::RA_AVAILABLE, "Support"))
;
return tid;
}
BindServer::BindServer (void)
{
m_localAddress = Ipv4Address ();
m_netMask = Ipv4Mask ();
m_socket = 0;
/* cstrctr */
}
BindServer::~BindServer ()
{
/* dstrctr */
}
void
BindServer::AddZone (std::string zone_name, uint32_t TTL, uint16_t ns_class, uint16_t type, std::string rData)
{
NS_LOG_FUNCTION (this << zone_name << TTL << ns_class << type << rData);
m_nsCache.AddZone (zone_name, ns_class, type, TTL, rData);
}
void
BindServer::StartApplication (void)
{
NS_LOG_FUNCTION (this);
// Start expiration of the DNS records after TTL values.
m_nsCache.SynchronizeTTL ();
if (m_socket == 0)
{
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
m_socket = Socket::CreateSocket (GetNode (), tid);
InetSocketAddress local = InetSocketAddress (m_localAddress, DNS_PORT);
m_socket->Bind (local);
}
m_socket->SetRecvCallback (MakeCallback (&BindServer::HandleQuery, this));
}
void
BindServer::StopApplication ()
{
NS_LOG_FUNCTION (this);
if (m_socket != 0)
{
m_socket->Close ();
m_socket->SetRecvCallback (MakeNullCallback <void, Ptr<Socket> > ());
}
DoDispose ();
}
void
BindServer::HandleQuery (Ptr<Socket> socket)
{
NS_LOG_FUNCTION (this << socket);
Ptr<Packet> message;
Address from;
while ((message = socket->RecvFrom (from)))
{
if (InetSocketAddress::IsMatchingType (from))
{
// TODO
//NS_LOG_INFO ()
}
message->RemoveAllPacketTags ();
message->RemoveAllByteTags ();
if (m_serverType == LOCAL_SERVER)
{
LocalServerService (message, from);
}
else if (m_serverType == ROOT_SERVER)
{
RootServerService (message, from);
}
else if (m_serverType == TLD_SERVER)
{
TLDServerService (message, from);
}
else if (m_serverType == ISP_SERVER)
{
ISPServerService (message, from);
}
else if (m_serverType == AUTH_SERVER)
{
AuthServerService (message, from);
}
else
{
NS_ABORT_MSG ("Name server should have a type. Hint: Set NameserverType. Aborting");
}
}
}
void
BindServer::LocalServerService (Ptr<Packet> nsQuery, Address toAddress)
{
NS_LOG_FUNCTION (this);
DNSHeader DnsHeader;
uint16_t qType, qClass;
std::string qName;
bool foundInCache = false;
bool nsQuestion = false;
nsQuery->RemoveHeader (DnsHeader);
if ((nsQuestion = DnsHeader.GetQRbit ())) // if NS query
{
// retrieve the question list
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
// Although the header supports multiple questions at a time
// the local DNS server is not yet implemented to resolve multiple questions at a time.
// We assume that clients generate separate DNS messages for each
// host that they wanted to resolve.
// NOTE
// We assumed that the local DNS does the recursive resolution process (i.e., in CDN networks)
qName = questionList.begin ()->GetqName ();
qType = questionList.begin ()->GetqType ();
qClass = questionList.begin ()->GetqClass ();
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordHas (qName, foundInCache);
// // Find the query in the nameserver cache
// SRVTable::SRVRecordInstance instance;
// foundInCache = m_nsCache.FindRecordsFor (qName, instance);
if (foundInCache)
{
NS_LOG_INFO ("Found a record in the local cache. Replying..");
// Local Server always returns the server address according to the RR manner.
Ptr<Packet> dnsResponse = Create<Packet> ();
ResourceRecordHeader answer;
answer.SetName (cachedRecord->first->GetRecordName ());
answer.SetClass (cachedRecord->first->GetClass ());
answer.SetType (cachedRecord->first->GetType ());
answer.SetTimeToLive (25);//cachedRecord->first->GetTTL ());
answer.SetRData (cachedRecord->first->GetRData ());
DnsHeader.AddAnswer (answer);
DnsHeader.SetRAbit (1);
dnsResponse->AddHeader (DnsHeader);
// Add the DNS header to the response packet and send it to the client
dnsResponse->AddHeader (DnsHeader);
ReplyQuery (dnsResponse, toAddress);
//Toggle servers
m_nsCache.SwitchServersRoundRobin ();
return;
}// end of query is found in cache
else if (!foundInCache && (m_raType == RA_AVAILABLE))
{
NS_LOG_INFO ("Initiate recursive resolution.");
Ptr<Packet> requestRR = Create<Packet> ();
std::string tld;
std::string::size_type found = 0;
bool foundTLDinCache = false;
// find the TLD of the query
found = qName.find_last_of ('.');
tld = qName.substr (found);
//Find the TLD in the nameserver cache
SRVTable::SRVRecordI cachedTLDRecord = m_nsCache.FindARecord (tld, foundTLDinCache);
requestRR->AddHeader (DnsHeader);
NS_LOG_INFO ("Add the recursive request in to the list");
m_recursiveQueryList [qName] = toAddress;
if (foundTLDinCache)
{
// Send to the TLD server
SendQuery (requestRR, InetSocketAddress (Ipv4Address (cachedTLDRecord->first->GetRData ().c_str ()), DNS_PORT));
}
else
{
// Send to the reqiest to the Root server
SendQuery (requestRR, InetSocketAddress (m_rootAddress, DNS_PORT));
}
return;
}// end of not found in cache and recursive resolution
}// end of the NS query
else // // NS response !rHeader.GetQRbit ()
{
NS_LOG_INFO ("Handle the NS responses from recursive name servers");
// NOTE
// In this implementation, the remaining bits of the OPCODE are used to specify the reply types.
// 3 for the replies from a ROOT server
// 4 for the replies from a TLD server
// 5 for the replies from a ISP's name server
// 6 fro the replies from a Authoritative name server (in this case the AA bit is also considered)
// All answers are append to the DNS header.
// However, only the relevant answer is taken according to the OPCODE value.
// Furthermore, we implemented the servers to add the resource record to the top of the answer section.
std::string forwardingAddress;
// retrieve the Answer list
std::list <ResourceRecordHeader> answerList;
answerList = DnsHeader.GetAnswerList ();
// Always use the most recent answer, so that the previous server is considered.
// However, the answer list contains all answers recursive name servers added.
qName = answerList.begin ()->GetName ();
qType = answerList.begin ()->GetType ();
qClass = answerList.begin ()->GetClass ();
forwardingAddress = answerList.begin ()->GetRData ();
if (DnsHeader.GetOpcode () == 3) // reply from the root server about a TLD server
{
NS_LOG_INFO ("Add the TLD record in to the server cache");
std::string tld;
std::string::size_type foundAt = 0;
foundAt = qName.find_last_of ('.');
tld = qName.substr (foundAt);
// add the record about TLD to the Local name server cache
m_nsCache.AddRecord (tld,
answerList.begin ()->GetClass (),
answerList.begin ()->GetType (),
answerList.begin ()->GetTimeToLive (),
answerList.begin ()->GetRData ());
// create a packet to send to TLD
Ptr<Packet> sendToTLD = Create<Packet> ();
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (0);
DnsHeader.SetQRbit (1);
sendToTLD->AddHeader (DnsHeader);
SendQuery (sendToTLD, InetSocketAddress (Ipv4Address (forwardingAddress.c_str ()), DNS_PORT));
}
else if (DnsHeader.GetOpcode () == 4)
{
Ptr<Packet> sendToISP = Create<Packet> ();
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (0);
DnsHeader.SetQRbit (1);
sendToISP->AddHeader (DnsHeader);
SendQuery (sendToISP, InetSocketAddress (Ipv4Address (forwardingAddress.c_str ()), DNS_PORT));
NS_LOG_INFO ("Contact ISP name server");
}
else if (DnsHeader.GetOpcode () == 5)
{
// If the ISP's name server says that it has the authoritative records,
// cache it and pass it to the user.
if (DnsHeader.GetAAbit ())
{
NS_LOG_INFO ("Add the Auth records in to the server cache");
std::list <ResourceRecordHeader>answerList;
answerList = DnsHeader.GetAnswerList ();
// Store all answers, i.e., server records, to the Local DNS cache
for (std::list<ResourceRecordHeader>::iterator iter = answerList.begin ();
iter != answerList.end ();
iter ++)
{
m_nsCache.AddRecord (iter->GetName (),
iter->GetClass (),
iter->GetType (),
/*iter->GetTimeToLive ()*/40,
iter->GetRData ());
}
// Clear the existing answer list
DnsHeader.ClearAnswers ();
// Get the recent query from the cache.
//TODO: This approach can be optimized
bool foundInCache = false;
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordHas (qName, foundInCache);
// Create the Answer and reply it back to the client
ResourceRecordHeader answer;
answer.SetName (cachedRecord->first->GetRecordName ());
answer.SetClass (cachedRecord->first->GetClass ());
answer.SetType (cachedRecord->first->GetType ());
answer.SetTimeToLive (25);//(cachedRecord->first->GetTTL ()); // bypassed for testing purposes
answer.SetRData (cachedRecord->first->GetRData ());
DnsHeader.AddAnswer (answer);
// create a packet to send to TLD
Ptr<Packet> replyToClient = Create<Packet> ();
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (0);
DnsHeader.SetQRbit (0);
DnsHeader.SetAAbit (1);
replyToClient->AddHeader (DnsHeader);
// Find the actual client query that stores in recursive list
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
ReplyQuery (replyToClient, m_recursiveQueryList.find (qName)->second);
m_recursiveQueryList.erase (qName);
m_nsCache.SwitchServersRoundRobin ();
}
else
{
Ptr<Packet> sendToAUTH = Create<Packet> ();
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (0);
DnsHeader.SetQRbit (1);
sendToAUTH->AddHeader (DnsHeader);
SendQuery (sendToAUTH, InetSocketAddress (Ipv4Address (forwardingAddress.c_str ()), DNS_PORT));
NS_LOG_INFO ("Contact Authoritative name server");
}
}
else if (DnsHeader.GetOpcode () == 6)
{
NS_LOG_INFO ("Add the Auth records in to the server cache");
std::list <ResourceRecordHeader>answerList;
answerList = DnsHeader.GetAnswerList ();
// Store all answers, i.e., server records, to the Local DNS cache
for (std::list<ResourceRecordHeader>::iterator iter = answerList.begin ();
iter != answerList.end ();
iter ++)
{
m_nsCache.AddRecord (iter->GetName (),
iter->GetClass (),
iter->GetType (),
iter->GetTimeToLive ()/*40*/,
iter->GetRData ());
}
// Clear the existing answer list
DnsHeader.ClearAnswers ();
// Get the recent query from the cache.
// TODO: This approach can be optimized
bool foundInCache = false;
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordHas (qName, foundInCache);
// Create the Answer and reply it back to the client
ResourceRecordHeader answer;
answer.SetName (cachedRecord->first->GetRecordName ());
answer.SetClass (cachedRecord->first->GetClass ());
answer.SetType (cachedRecord->first->GetType ());
answer.SetTimeToLive (25);//(cachedRecord->first->GetTTL ()); // bypassed for testing purposes
answer.SetRData (cachedRecord->first->GetRData ());
DnsHeader.AddAnswer (answer);
// create a packet to send to TLD
Ptr<Packet> replyToClient = Create<Packet> ();
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (0);
DnsHeader.SetQRbit (0);
DnsHeader.SetAAbit (1);
replyToClient->AddHeader (DnsHeader);
// Find the actual client query that stores in recursive list
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
ReplyQuery (replyToClient, m_recursiveQueryList.find (qName)->second);
m_recursiveQueryList.erase (qName);
m_nsCache.SwitchServersRoundRobin ();
}
else
{
//TODO
// Abort with a error message
}
} // end of ns response
}
void
BindServer::RootServerService (Ptr<Packet> nsQuery, Address toAddress)
{
// Assumptions made to Create the ROOT name server
// Root name servers never create any NS requests.
DNSHeader DnsHeader;
uint16_t qType, qClass;
std::string qName;
bool foundInCache = false;
nsQuery->RemoveHeader (DnsHeader);
// Assume that only one question is attached to the DNS header
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
qType = questionList.begin ()->GetqType ();
qClass = questionList.begin ()->GetqClass ();
// Return the first record that matches the requested qName
// This supports the RR method
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordMatches (qName, foundInCache);
if (foundInCache)
{
Ptr<Packet> rootResponse = Create<Packet> ();
ResourceRecordHeader rrHeader;
rrHeader.SetName (cachedRecord->first->GetRecordName ());
rrHeader.SetClass (cachedRecord->first->GetClass ());
rrHeader.SetType (cachedRecord->first->GetType ());
rrHeader.SetTimeToLive (cachedRecord->first->GetTTL ());
rrHeader.SetRData (cachedRecord->first->GetRData ());
DnsHeader.SetQRbit (0);
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (3);
DnsHeader.AddAnswer (rrHeader);
rootResponse->AddHeader (DnsHeader);
ReplyQuery (rootResponse, toAddress);
}
else
{
//TODO
// Send a reply contains RCODE = 3
}
}
void
BindServer::TLDServerService (Ptr<Packet> nsQuery, Address toAddress)
{
DNSHeader DnsHeader;
uint16_t qType, qClass;
std::string qName;
bool foundInCache = false;
nsQuery->RemoveHeader (DnsHeader);
// Assume that only one question is attached to the DNS header
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
qType = questionList.begin ()->GetqType ();
qClass = questionList.begin ()->GetqClass ();
// Return the first record that matches the requested qName
// This supports the RR method
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordMatches (qName, foundInCache);
if (foundInCache)
{
Ptr<Packet> tldResponse = Create<Packet> ();
ResourceRecordHeader rrHeader;
rrHeader.SetName (cachedRecord->first->GetRecordName ());
rrHeader.SetClass (cachedRecord->first->GetClass ());
rrHeader.SetType (cachedRecord->first->GetType ());
rrHeader.SetTimeToLive (cachedRecord->first->GetTTL ());
rrHeader.SetRData (cachedRecord->first->GetRData ());
DnsHeader.SetQRbit (0);
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (4);
DnsHeader.AddAnswer (rrHeader);
tldResponse->AddHeader (DnsHeader);
ReplyQuery (tldResponse, toAddress);
}
else
{
//TODO
// Send a reply contains RCODE = 3
}
}
void
BindServer::ISPServerService (Ptr<Packet> nsQuery, Address toAddress)
{
DNSHeader DnsHeader;
uint16_t qType, qClass;
std::string qName;
bool foundInCache = false, foundAuthRecordinCache = false;
nsQuery->RemoveHeader (DnsHeader);
// Assume that only one question is attached to the DNS header
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
qType = questionList.begin ()->GetqType ();
qClass = questionList.begin ()->GetqClass ();
// Find for a record that exactly matches the query name.
// if the query is exactly matches for a record in the ISP cache,
// the record is treated as a Authoritative record for the client.
// In case the ISP name server could not find a auth. record for the query,
// the ISP name server returns IP addresses of the Authoritative name servers
// for the requested name.
// To make the load distribution, we assumed the RR implementation for authoritative records.
SRVTable::SRVRecordI foundAuthRecord = m_nsCache.FindARecord (qName, foundAuthRecordinCache);
// Return the first record that matches the requested qName
// This supports the RR method
SRVTable::SRVRecordI cachedRecord = m_nsCache.FindARecordMatches (qName, foundInCache);
Ptr<Packet> ispResponse = Create<Packet> ();
if (foundAuthRecordinCache)
{
// Move the existing answer list to the Additional section.
// This feature is implemented to track the recursive operation and
// thus for debugging purposes.
// Assume that only one question is attached to the DNS header
NS_LOG_INFO ("Move the Existing recursive answer list in to additional section.");
std::list <ResourceRecordHeader>answerList;
answerList = DnsHeader.GetAnswerList ();
for (std::list<ResourceRecordHeader>::iterator iter = answerList.begin ();
iter != answerList.end ();
iter ++)
{
ResourceRecordHeader additionalRecord;
additionalRecord.SetName (iter->GetName ());
additionalRecord.SetClass (iter->GetClass ());
additionalRecord.SetType (iter->GetType ());
additionalRecord.SetTimeToLive (iter->GetTimeToLive ());
additionalRecord.SetRData (iter->GetRData ());
DnsHeader.AddARecord (additionalRecord);
}
// Clear the existing answer list
DnsHeader.ClearAnswers ();
ResourceRecordHeader rrHeader;
rrHeader.SetName (foundAuthRecord->first->GetRecordName ());
rrHeader.SetClass (foundAuthRecord->first->GetClass ());
rrHeader.SetType (foundAuthRecord->first->GetType ());
rrHeader.SetTimeToLive (foundAuthRecord->first->GetTTL ());
rrHeader.SetRData (foundAuthRecord->first->GetRData ());
DnsHeader.SetQRbit (0);
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (5);
DnsHeader.SetAAbit (1);
DnsHeader.AddAnswer (rrHeader);
ispResponse->AddHeader (DnsHeader);
ReplyQuery (ispResponse, toAddress);
// Change the order of server according to the round robin algorithm
m_nsCache.SwitchServersRoundRobin ();
}
else if (foundInCache)
{
ResourceRecordHeader rrHeader;
rrHeader.SetName (cachedRecord->first->GetRecordName ());
rrHeader.SetClass (cachedRecord->first->GetClass ());
rrHeader.SetType (cachedRecord->first->GetType ());
rrHeader.SetTimeToLive (cachedRecord->first->GetTTL ());
rrHeader.SetRData (cachedRecord->first->GetRData ());
DnsHeader.SetQRbit (0);
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (5);
DnsHeader.AddAnswer (rrHeader);
ispResponse->AddHeader (DnsHeader);
ReplyQuery (ispResponse, toAddress);
}
else
{
//TODO
// Send a reply contains RCODE = 3
}
}
void
BindServer::AuthServerService (Ptr<Packet> nsQuery, Address toAddress)
{
DNSHeader DnsHeader;
uint16_t qType, qClass;
std::string qName;
bool foundInCache = false;//, foundAARecords = false;
nsQuery->RemoveHeader (DnsHeader);
// Assume that only one question is attached to the DNS header
std::list <QuestionSectionHeader> questionList;
questionList = DnsHeader.GetQuestionList ();
qName = questionList.begin ()->GetqName ();
qType = questionList.begin ()->GetqType ();
qClass = questionList.begin ()->GetqClass ();
NS_UNUSED (foundInCache);
// Find the query in the nameserver cache
SRVTable::SRVRecordInstance instance;
//foundInCache = m_nsCache.FindRecordsFor (qName, instance);
foundInCache = m_nsCache.FindAllRecordsHas (qName, instance);
if (foundInCache)
{
// Move the existing answer list to the Additional section.
// This feature is implemented to track the recursive operation and
// thus for debugging purposes.
// Assume that only one question is attached to the DNS header
NS_LOG_INFO ("Move the Existing recursive answer list in to additional section.");
std::list <ResourceRecordHeader>answerList;
answerList = DnsHeader.GetAnswerList ();
for (std::list<ResourceRecordHeader>::iterator iter = answerList.begin ();
iter != answerList.end ();
iter ++)
{
ResourceRecordHeader additionalRecord;
additionalRecord.SetName (iter->GetName ());
additionalRecord.SetClass (iter->GetClass ());
additionalRecord.SetType (iter->GetType ());
additionalRecord.SetTimeToLive (iter->GetTimeToLive ());
additionalRecord.SetRData (iter->GetRData ());
DnsHeader.AddARecord (additionalRecord);
}
// Clear the existing answer list
DnsHeader.ClearAnswers ();
// Now, add the server list as the new answer list
NS_LOG_INFO ("Add the content server list as the new answer list of the DNS header.");
// Create the response
Ptr<Packet> authResponse = Create<Packet> ();
// Get the found record list and add the records to the DNS header according to the Type
for (SRVTable::SRVRecordI it = instance.begin (); it != instance.end (); it++)
{
// Assume that Number of DNS records will note results packet segmentation
if (it->first->GetType () == 1) // A host record or a CNAME record
{
ResourceRecordHeader rrHeader;
rrHeader.SetName (it->first->GetRecordName ());
rrHeader.SetClass (it->first->GetClass ());
rrHeader.SetType (it->first->GetType ());
rrHeader.SetTimeToLive (it->first->GetTTL ());
rrHeader.SetRData (it->first->GetRData ());
DnsHeader.AddAnswer (rrHeader);
}
if (it->first->GetType () == 2) // A Authoritative Name server record
{
ResourceRecordHeader nsRecord;
nsRecord.SetName (it->first->GetRecordName ());
nsRecord.SetClass (it->first->GetClass ());
nsRecord.SetType (it->first->GetType ());
nsRecord.SetTimeToLive (it->first->GetTTL ());
nsRecord.SetRData (it->first->GetRData ());
DnsHeader.AddNsRecord (nsRecord);
}
if (it->first->GetType () == 5) // A Authoritative Name server record
{
ResourceRecordHeader rrRecord;
rrRecord.SetName (it->first->GetRecordName ());
rrRecord.SetClass (it->first->GetClass ());
rrRecord.SetType (it->first->GetType ());
rrRecord.SetTimeToLive (it->first->GetTTL ());
rrRecord.SetRData (it->first->GetRData ());
DnsHeader.AddNsRecord (rrRecord);
}
}
DnsHeader.SetQRbit (0);
DnsHeader.SetAAbit (1);
DnsHeader.ResetOpcode ();
DnsHeader.SetOpcode (6);
authResponse->AddHeader (DnsHeader);
ReplyQuery (authResponse, toAddress);
// Change the order of server according to the round robin algorithm
m_nsCache.SwitchServersRoundRobin ();
}
else
{
// TODO
// Send a reply contains RCODE = 3
}
}
void
BindServer::SendQuery (Ptr<Packet> requestRecord, Address toAddress)
{
NS_LOG_FUNCTION (this <<
requestRecord <<
InetSocketAddress::ConvertFrom (toAddress).GetIpv4 () <<
InetSocketAddress::ConvertFrom (toAddress).GetPort ());
NS_LOG_INFO ("Server " <<
m_localAddress <<
" send a reply to " <<
InetSocketAddress::ConvertFrom (toAddress).GetIpv4 ());
m_socket->SendTo (requestRecord, 0, toAddress);
}
void
BindServer::ReplyQuery (Ptr<Packet> nsQuery, Address toAddress)
{
NS_LOG_FUNCTION (this <<
nsQuery <<
InetSocketAddress::ConvertFrom (toAddress).GetIpv4 () <<
InetSocketAddress::ConvertFrom (toAddress).GetPort ());
NS_LOG_INFO ("Server " <<
m_localAddress <<
" send a reply to " <<
InetSocketAddress::ConvertFrom (toAddress).GetIpv4 ());
m_socket->SendTo (nsQuery, 0, toAddress);
}
}
| [
"janaka@west.sd.keio.ac.jp"
] | janaka@west.sd.keio.ac.jp |
bce881acc8404883b4708b6255558d79aaa48ca8 | 0463891cdff68d4d1b9adb601a3874e4a6d23b94 | /include/network/message.h | 2dde678cc5b4e337a198eff9e2b3156f4e809f72 | [] | no_license | Notgnoshi/clipd | 3e58df74b3c128c604a437b485fe5dd65d3caec3 | f41dc25d3cc54adea9a7a711a526c575c98f2064 | refs/heads/master | 2020-07-31T03:39:58.704515 | 2019-12-11T21:34:30 | 2019-12-11T21:34:30 | 210,470,376 | 1 | 0 | null | 2019-12-11T17:21:07 | 2019-09-23T23:30:07 | C++ | UTF-8 | C++ | false | false | 5,513 | h | #pragma once
#include <zyre.h>
#include <iostream>
#include <string>
#include <variant>
namespace Clipd::Network::Messages
{
enum class MessageType
{
Enter, //!< A new peer has joined the network.
Exit, //!< A peer has explicitly left the network.
Evasive, //!< A peer hasn't been heard from recently.
Join, //!< A peer has joined a group.
Leave, //!< A peer has left a group.
Whisper, //!< A peer has messaged a particular node.
Shout, //!< A peer has broadcast a message to an entire group.
Unknown, //!< Something else has happend?!
};
struct Enter
{
std::string uuid;
std::string name;
std::string headers;
std::string address;
Enter( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
headers = std::string( zmsg_popstr( msg ) );
address = std::string( zmsg_popstr( msg ) );
}
};
struct Exit
{
std::string uuid;
std::string name;
Exit( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
}
};
struct Evasive
{
std::string uuid;
std::string name;
Evasive( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
}
};
struct Join
{
std::string uuid;
std::string name;
std::string groupname;
Join( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
groupname = std::string( zmsg_popstr( msg ) );
}
};
struct Leave
{
std::string uuid;
std::string name;
std::string groupname;
Leave( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
groupname = std::string( zmsg_popstr( msg ) );
}
};
struct Whisper
{
std::string uuid;
std::string name;
std::string message;
Whisper( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
message = std::string( zmsg_popstr( msg ) );
}
};
struct Shout
{
std::string uuid;
std::string name;
std::string groupname;
std::string message;
Shout( zmsg_t* msg )
{
uuid = std::string( zmsg_popstr( msg ) );
name = std::string( zmsg_popstr( msg ) );
groupname = std::string( zmsg_popstr( msg ) );
message = std::string( zmsg_popstr( msg ) );
}
};
//! @brief Convert a zframe_t to a string.
static std::string parseFrameStr( zframe_t* frame )
{
return std::string( reinterpret_cast<char*>( zframe_data( frame ) ), zframe_size( frame ) );
}
/**
* @brief Parse the first frame from the message to determine the Zyre message type.
*
* @param msg The message to parse as a Zyre message.
* @return The type of the Zyre message
*/
MessageType parseMessageType( zmsg_t* msg )
{
zframe_t* frame = zmsg_pop( msg );
std::string type = parseFrameStr( frame );
if( type == "ENTER" )
{
return MessageType::Enter;
}
else if( type == "EXIT" )
{
return MessageType::Exit;
}
else if( type == "EVASIVE" )
{
return MessageType::Evasive;
}
else if( type == "JOIN" )
{
return MessageType::Join;
}
else if( type == "LEAVE" )
{
return MessageType::Leave;
}
else if( type == "WHISPER" )
{
return MessageType::Whisper;
}
else if( type == "SHOUT" )
{
return MessageType::Shout;
}
return MessageType::Unknown;
}
std::ostream& operator<<( std::ostream& o, const Enter& msg )
{
o << "Enter:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
o << "\theaders: " << msg.headers << std::endl;
o << "\taddress: " << msg.address << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Exit& msg )
{
o << "Exit:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Evasive& msg )
{
o << "Evasive:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Join& msg )
{
o << "Join:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
o << "\tgroupname: " << msg.groupname << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Leave& msg )
{
o << "Leave:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
o << "\tgroupname: " << msg.groupname << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Whisper& msg )
{
o << "Whisper:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
o << "\tmessage: " << msg.message << std::endl;
return o;
}
std::ostream& operator<<( std::ostream& o, const Shout& msg )
{
o << "Shout:" << std::endl;
o << "\tuuid: " << msg.uuid << std::endl;
o << "\tname: " << msg.name << std::endl;
o << "\tgroupname: " << msg.groupname << std::endl;
o << "\tmessage: " << msg.message << std::endl;
return o;
}
} // namespace Clipd::Network::Messages
| [
"Notgnoshi@users.noreply.github.com"
] | Notgnoshi@users.noreply.github.com |
1d2fb7d5be9ae3ee73d767b58de06a1872d3974b | b0351f5e1e68b8272b5589f2abb792a157b918a9 | /SpaDomacaZadaca01/Cvijet.cpp | 17c872b9add84d93d279855501e762aee3a696f3 | [] | no_license | hrvojemarsic/rvs19-spa-dz-01 | 0d28f8f6b73e509e61910e41bc81805dd5777b75 | 75839015d3b5080292305d4691d1e5e74441c3cb | refs/heads/master | 2021-04-21T17:00:52.853649 | 2020-04-08T09:57:13 | 2020-04-08T09:57:13 | 249,798,117 | 0 | 0 | null | 2020-03-24T19:23:20 | 2020-03-24T19:23:19 | null | UTF-8 | C++ | false | false | 2,732 | cpp | #include "Cvijet.h"
#include <cmath>
using namespace std;
using namespace sf;
Cvijet::Cvijet(RenderWindow* window)
{
this->window = window;
}
void Cvijet::draw()
{
frameClock.restart();
float r_sunca = 40.0f;
float x_sunca = 0.0f;
float y_sunca = 25.0f;
float r_latice = 20.0f;
float x_latice = 200.0f;
float y_latice = 200.0f;
float r_kruga = 60.0f;
double omjer = (0.92 + (r_latice / r_kruga));
float x_krug = x_latice / omjer;
float y_krug = y_latice / omjer;
float x_stabljike = x_latice + 10;
float y_stabljike = y_latice;
stabljika.setPosition(Vector2f(x_stabljike, y_stabljike));
stabljika.setSize(Vector2f(20.0f, 400.0f));
stabljika.setFillColor(Color::Green);
desni_list.setPointCount(5);
desni_list.setPoint(0, Vector2f(x_stabljike, (y_stabljike + 200)));
desni_list.setPoint(1, Vector2f((x_stabljike + 100), (y_stabljike + 110)));
desni_list.setPoint(2, Vector2f((x_stabljike + 180), (y_stabljike + 130)));
desni_list.setPoint(3, Vector2f((x_stabljike + 120), (y_stabljike + 180)));
desni_list.setPoint(4, Vector2f(x_stabljike, (y_stabljike + 200)));
desni_list.setFillColor(Color::Green);
lijevi_list.setPointCount(5);
lijevi_list.setPoint(0, Vector2f(x_stabljike, (y_stabljike + 300)));
lijevi_list.setPoint(1, Vector2f((x_stabljike - 120), (y_stabljike + 280)));
lijevi_list.setPoint(2, Vector2f((x_stabljike - 160), (y_stabljike + 230)));
lijevi_list.setPoint(3, Vector2f((x_stabljike - 100), (y_stabljike + 210)));
lijevi_list.setPoint(4, Vector2f(x_stabljike, (y_stabljike + 290)));
lijevi_list.setFillColor(Color::Green);
krug.setRadius(r_kruga);
krug.setOutlineColor(Color::Green);
krug.setFillColor(Color::Yellow);
krug.setOutlineThickness(2);
krug.setPosition(x_krug, y_krug);
int pozicija_sunca = 0;
do
{
window->clear();
window->draw(stabljika);
window->draw(desni_list);
window->draw(lijevi_list);
window->draw(krug);
int broj_latica = 12;
int i = 1;
do
{
float razmak = 2 * 3.14 / broj_latica;
latica.setRadius(r_latice);
latica.setFillColor(Color::Red);
latica.setPosition(x_latice, y_latice);
latica.setOrigin((r_latice + r_kruga) * sin(i * razmak), (r_latice + r_kruga) * cos(i * razmak));
latica.setOutlineColor(Color::Green);
latica.setOutlineThickness(2);
window->draw(latica);
i++;
} while (i <= broj_latica);
window->draw(sunce);
window->display();
sunce.setPosition((x_sunca + pozicija_sunca), y_sunca);
sunce.setRadius(r_sunca);
sunce.setFillColor(Color::Yellow);
sunce.setOutlineThickness(1);
sunce.setOutlineColor(Color::Red);
window->draw(sunce);
Time t = frameClock.getElapsedTime();
if (t.asSeconds() > 0.01)
{
pozicija_sunca++;
}
} while (pozicija_sunca < 850);
}
| [
"marsic.hrvoje@gmail.com"
] | marsic.hrvoje@gmail.com |
2f3cee47f9f0c06bb3e1d69b5e663e203e74fe4c | 1d661088650ed46e1421908b5a16b086d70fef4f | /src/test/discrete_tomography_chain.cpp | 9cabe1805e91286ea78ab22e783340c5d43dc442 | [] | no_license | sunbirddy/LP_MP | d08cc619d6ee882f0433f5313e55d32cf35794ff | 519ce42ad747d90dbd1c99346dbe638beaecf145 | refs/heads/master | 2021-01-02T09:17:58.095429 | 2017-06-07T12:38:32 | 2017-06-07T12:38:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,580 | cpp | #include "catch.hpp"
#include <vector>
#include "visitors/standard_visitor.hxx"
#include "solvers/discrete_tomography/discrete_tomography.h"
using namespace LP_MP;
using namespace std;
// to do: check correctness for pure sequential, pure recursive and mixed constructor on chains
template<typename SOLVER>
void add_projection_and_run(SOLVER& s, std::vector<INDEX> projection_var, const INDEX projection_sum)
{
auto& dt = s.template GetProblemConstructor<1>();
std::vector<REAL> projectionCost(projection_sum+1);
std::fill(projectionCost.begin(), projectionCost.end(), std::numeric_limits<REAL>::infinity());
projectionCost.back() = 0.0;
dt.AddProjection(projection_var, projectionCost);
s.Solve();
if((projection_sum) % 10 != 0) {
assert(std::abs(s.lower_bound() - 1.0) < eps);
REQUIRE(std::abs(s.lower_bound() - 1.0) < eps);
REQUIRE(std::abs(s.primal_cost() - 1.0) < eps);
} else {
assert(std::abs(s.lower_bound()) < eps);
REQUIRE(std::abs(s.lower_bound()) < eps);
REQUIRE(std::abs(s.primal_cost()) < eps);
}
}
template<typename SOLVER>
void add_projection_and_unaries_and_run(SOLVER& s, std::vector<INDEX> projection_var, const INDEX projection_sum, const REAL cost)
{
auto& dt = s.template GetProblemConstructor<1>();
std::vector<REAL> projectionCost(projection_sum+1);
std::fill(projectionCost.begin(), projectionCost.end(), std::numeric_limits<REAL>::infinity());
projectionCost.back() = 0.0;
dt.AddProjection(projection_var, projectionCost);
s.Solve();
assert(std::abs(s.lower_bound() - cost) < eps);
REQUIRE(std::abs(s.lower_bound() - cost) < eps);
REQUIRE(std::abs(s.primal_cost() - cost) < eps);
}
TEST_CASE("discrete tomography single chain", "[dt chain]") {
char * options[5];
options[0] = "";
options[1] = "-i";
options[2] = "";
options[3] = "--maxIter";
options[4] = "1000";
MpRoundingSolver<Solver<FMC_DT,LP_sat<LP>,StandardVisitor>> s(5,options);
// add single Potts chain of length 10 with varying summation costs
const INDEX noLabels = 3;
matrix<REAL> PottsCost(3,3,0.0);
for(INDEX x1=0; x1<noLabels; ++x1) {
for(INDEX x2=0; x2<noLabels; ++x2) {
if(x1 != x2) {
PottsCost(x1,x2) = 1.0;
}
}
}
assert(PottsCost(0,0) == 0.0 && PottsCost(0,0) == 0.0 && PottsCost(0,0) == 0.0);
auto& mrf = s.template GetProblemConstructor<0>();
for(INDEX i=0; i<10; ++i) {
mrf.AddUnaryFactor(i,{0.0,0.0,0.0});
}
for(INDEX i=1; i<10; ++i) {
mrf.AddPairwiseFactor(i-1,i,PottsCost);
}
auto& dt = s.template GetProblemConstructor<1>();
dt.SetNumberOfLabels(3);
std::vector<INDEX> projection_var {0,1,2,3,4,5,6,7,8,9};
SECTION("sum = 0") { add_projection_and_run(s, projection_var, 0); }
SECTION("sum = 1") { add_projection_and_run(s, projection_var, 1); }
SECTION("sum = 2") { add_projection_and_run(s, projection_var, 2); }
SECTION("sum = 3") { add_projection_and_run(s, projection_var, 3); }
SECTION("sum = 4") { add_projection_and_run(s, projection_var, 4); }
SECTION("sum = 5") { add_projection_and_run(s, projection_var, 5); }
SECTION("sum = 6") { add_projection_and_run(s, projection_var, 6); }
SECTION("sum = 7") { add_projection_and_run(s, projection_var, 7); }
SECTION("sum = 8") { add_projection_and_run(s, projection_var, 8); }
SECTION("sum = 9") { add_projection_and_run(s, projection_var, 9); }
SECTION("sum = 10") { add_projection_and_run(s, projection_var, 10); }
SECTION("sum = 11") { add_projection_and_run(s, projection_var, 11); }
SECTION("sum = 12") { add_projection_and_run(s, projection_var, 12); }
SECTION("sum = 13") { add_projection_and_run(s, projection_var, 13); }
SECTION("sum = 14") { add_projection_and_run(s, projection_var, 14); }
SECTION("sum = 15") { add_projection_and_run(s, projection_var, 15); }
SECTION("sum = 16") { add_projection_and_run(s, projection_var, 16); }
SECTION("sum = 17") { add_projection_and_run(s, projection_var, 17); }
SECTION("sum = 18") { add_projection_and_run(s, projection_var, 18); }
SECTION("sum = 19") { add_projection_and_run(s, projection_var, 19); }
SECTION("sum = 20") { add_projection_and_run(s, projection_var, 20); }
// repeat with different unaries
for(INDEX i=0; i<10; ++i) {
auto& f = *mrf.GetUnaryFactor(i)->GetFactor();
f[0] += 2.0;
f[1] += 1.0;
}
SECTION("sum = 0 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 0, 20); }
SECTION("sum = 1 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 1, 20); }
SECTION("sum = 2 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 2, 19); }
SECTION("sum = 3 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 3, 18); }
SECTION("sum = 4 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 4, 17); }
SECTION("sum = 5 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 5, 16); }
SECTION("sum = 6 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 6, 15); }
SECTION("sum = 7 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 7, 14); }
SECTION("sum = 8 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 8, 13); }
SECTION("sum = 9 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 9, 12); }
SECTION("sum = 10 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 10, 10); }
SECTION("sum = 11 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 11, 10); }
SECTION("sum = 12 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 12, 9); }
SECTION("sum = 13 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 13, 8); }
SECTION("sum = 14 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 14, 7); }
SECTION("sum = 15 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 15, 6); }
SECTION("sum = 16 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 16, 5); }
SECTION("sum = 17 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 17, 4); }
SECTION("sum = 18 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 18, 3); }
SECTION("sum = 19 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 19, 2); }
SECTION("sum = 20 with unaries") { add_projection_and_unaries_and_run(s, projection_var, 20, 0); }
}
| [
"pswoboda@lnvlko005.ist.local"
] | pswoboda@lnvlko005.ist.local |
afa4db9138852fd544ceb632de7050e1fb30eea4 | 374dd4a9cc8bc02697361249b1617287f04134ed | /Include/Rendering/RenderComponent.h | d96a996e3d96cfc079a6dc7b71846cd03e4aaa11 | [] | no_license | pandeiros/VulkanEngine | eb0c5b5efcfa6a34ad16a5f0c6bc1415d8cfb99d | f33c29d1131ab89c2272e19f277cf715266a09aa | refs/heads/master | 2021-03-19T16:30:19.284100 | 2018-03-20T02:47:37 | 2018-03-20T02:47:37 | 72,582,977 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 948 | h | /**
* Vulkan Engine
*
* Copyright (C) 2016-2018 Pawel Kaczynski
*/
#pragma once
#include "VulkanCore.h"
#include "Utils/Math.h"
/**
* @file RenderComponent.h
*/
VULKAN_NS_BEGIN
#define XYZ1(X, Y, Z) (X), (Y), (Z), 1.f
#define COLOR_FLAT(R, G, B) XYZ1(R, G, B)
struct Vertex
{
// Position
float x, y, z, w;
// Color
float r, g, b, a;
};
struct VertexUV
{
// Position
float x, y, z, w;
// UV
float u, v;
};
typedef std::vector<Vertex> VertexData;
typedef std::vector<size_t> ShaderIndexData;
static const Transform DEFAULT_TRANSFORM = Transform(glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));
/**
* @class RenderComponent
*/
class RenderComponent
{
public:
void* GetData(uint32_t& dataSize, uint32_t& dataStride);
void SetVertexData(VertexData& vertexData);
ShaderIndexData& GetShaderIndexData();
protected:
VertexData vertices;
ShaderIndexData shaders;
};
VULKAN_NS_END | [
"milordpanda@gmail.com"
] | milordpanda@gmail.com |
f593574f8384c030457297a9cba884e8446931ef | 720ae1c51a03d0a3b2b8689c051ef02e63a532ca | /src/common/ExtAPIMessages_m.h | f144fbc3c6a2a3121ba5aa26cc63749adceb06fc | [] | no_license | peterpangl/soma_grid | 5329159be4cdd21cdc35842d91042ba3c9e3ac2f | cacde471924c49230850cdbba6789850bafc6529 | refs/heads/master | 2021-01-15T10:58:11.120416 | 2017-10-15T11:57:18 | 2017-10-15T11:57:18 | 99,606,032 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,232 | h | //
// Generated file, do not edit! Created by opp_msgc 4.2 from common/ExtAPIMessages.msg.
//
#ifndef _EXTAPIMESSAGES_M_H_
#define _EXTAPIMESSAGES_M_H_
#include <omnetpp.h>
// opp_msgc version check
#define MSGC_VERSION 0x0402
#if (MSGC_VERSION!=OMNETPP_VERSION)
# error Version mismatch! Probably this file was generated by an earlier version of opp_msgc: 'make clean' should help.
#endif
// cplusplus {{
#include <CommonMessages_m.h>
static const int GIAAPPCOMMAND_L = 8;
#define GIASEARCHAPP_L(msg) (GIAAPPCOMMAND_L)
#define GIAPUT_L(msg) (GIASEARCHAPP_L(msg) + msg->getKeysArraySize() * KEY_L)
#define GIAGET_L(msg) (GIASEARCHAPP_L(msg) + KEY_L + MAXRESPONSES_L)
#define GIAGETRSP_L(msg) (GIASEARCHAPP_L(msg) + KEY_L + NODEHANDLE_L)
// }}
/**
* Enum generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* enum GIAAppCommand
* {
*
* GIA_PUT = 0;
* GIA_SEARCH = 1;
* GIA_ANSWER = 2;
* }
* </pre>
*/
enum GIAAppCommand {
GIA_PUT = 0,
GIA_SEARCH = 1,
GIA_ANSWER = 2
};
/**
* Class generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* packet GIASearchAppMessage
* {
* int command enum (GIAAppCommand);
* }
* </pre>
*/
class GIASearchAppMessage : public ::cPacket
{
protected:
int command_var;
private:
void copy(const GIASearchAppMessage& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const GIASearchAppMessage&);
public:
GIASearchAppMessage(const char *name=NULL, int kind=0);
GIASearchAppMessage(const GIASearchAppMessage& other);
virtual ~GIASearchAppMessage();
GIASearchAppMessage& operator=(const GIASearchAppMessage& other);
virtual GIASearchAppMessage *dup() const {return new GIASearchAppMessage(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
virtual int getCommand() const;
virtual void setCommand(int command);
};
inline void doPacking(cCommBuffer *b, GIASearchAppMessage& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, GIASearchAppMessage& obj) {obj.parsimUnpack(b);}
/**
* Class generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* packet GIAput extends GIASearchAppMessage
* {
* OverlayKey keys[];
* }
* </pre>
*/
class GIAput : public ::GIASearchAppMessage
{
protected:
OverlayKey *keys_var; // array ptr
unsigned int keys_arraysize;
private:
void copy(const GIAput& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const GIAput&);
public:
GIAput(const char *name=NULL, int kind=0);
GIAput(const GIAput& other);
virtual ~GIAput();
GIAput& operator=(const GIAput& other);
virtual GIAput *dup() const {return new GIAput(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
virtual void setKeysArraySize(unsigned int size);
virtual unsigned int getKeysArraySize() const;
virtual OverlayKey& getKeys(unsigned int k);
virtual const OverlayKey& getKeys(unsigned int k) const {return const_cast<GIAput*>(this)->getKeys(k);}
virtual void setKeys(unsigned int k, const OverlayKey& keys);
};
inline void doPacking(cCommBuffer *b, GIAput& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, GIAput& obj) {obj.parsimUnpack(b);}
/**
* Class generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* packet GIAremove extends GIASearchAppMessage
* {
* }
* </pre>
*/
class GIAremove : public ::GIASearchAppMessage
{
protected:
private:
void copy(const GIAremove& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const GIAremove&);
public:
GIAremove(const char *name=NULL, int kind=0);
GIAremove(const GIAremove& other);
virtual ~GIAremove();
GIAremove& operator=(const GIAremove& other);
virtual GIAremove *dup() const {return new GIAremove(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
};
inline void doPacking(cCommBuffer *b, GIAremove& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, GIAremove& obj) {obj.parsimUnpack(b);}
/**
* Class generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* packet GIAsearch extends GIASearchAppMessage
* {
* OverlayKey searchKey;
* int maxResponses;
* }
* </pre>
*/
class GIAsearch : public ::GIASearchAppMessage
{
protected:
OverlayKey searchKey_var;
int maxResponses_var;
private:
void copy(const GIAsearch& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const GIAsearch&);
public:
GIAsearch(const char *name=NULL, int kind=0);
GIAsearch(const GIAsearch& other);
virtual ~GIAsearch();
GIAsearch& operator=(const GIAsearch& other);
virtual GIAsearch *dup() const {return new GIAsearch(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
virtual OverlayKey& getSearchKey();
virtual const OverlayKey& getSearchKey() const {return const_cast<GIAsearch*>(this)->getSearchKey();}
virtual void setSearchKey(const OverlayKey& searchKey);
virtual int getMaxResponses() const;
virtual void setMaxResponses(int maxResponses);
};
inline void doPacking(cCommBuffer *b, GIAsearch& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, GIAsearch& obj) {obj.parsimUnpack(b);}
/**
* Class generated from <tt>common/ExtAPIMessages.msg</tt> by opp_msgc.
* <pre>
* packet GIAanswer extends GIASearchAppMessage
* {
* OverlayKey searchKey;
* NodeHandle node;
* }
* </pre>
*/
class GIAanswer : public ::GIASearchAppMessage
{
protected:
OverlayKey searchKey_var;
NodeHandle node_var;
private:
void copy(const GIAanswer& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const GIAanswer&);
public:
GIAanswer(const char *name=NULL, int kind=0);
GIAanswer(const GIAanswer& other);
virtual ~GIAanswer();
GIAanswer& operator=(const GIAanswer& other);
virtual GIAanswer *dup() const {return new GIAanswer(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
virtual OverlayKey& getSearchKey();
virtual const OverlayKey& getSearchKey() const {return const_cast<GIAanswer*>(this)->getSearchKey();}
virtual void setSearchKey(const OverlayKey& searchKey);
virtual NodeHandle& getNode();
virtual const NodeHandle& getNode() const {return const_cast<GIAanswer*>(this)->getNode();}
virtual void setNode(const NodeHandle& node);
};
inline void doPacking(cCommBuffer *b, GIAanswer& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, GIAanswer& obj) {obj.parsimUnpack(b);}
#endif // _EXTAPIMESSAGES_M_H_
| [
"xubuntu@xubuntu-VirtualBox.(none)"
] | xubuntu@xubuntu-VirtualBox.(none) |
321cc2cdb882868724c1e671b5e75c3d610a686d | 995e57d48d59cca908abea3190e0b1cd38472dc1 | /src/main.cpp | 46b8f907a09da6074ca4dee8bf861a9ab7480ad2 | [] | no_license | Veluga/chip8-emu | fd050ebcdffc60425cf83bdc16a17d72a4dcf7d4 | 072b25495828a45a7aca62dd9a4bd19cbe38c96a | refs/heads/master | 2022-04-09T04:50:09.334931 | 2020-03-29T16:23:26 | 2020-03-29T16:23:26 | 249,922,450 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,876 | cpp | #include <stdio.h>
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
#include <SDL2/SDL.h>
#include "chip8.hpp"
int main()
{
// Emu Setup
Chip8 chip8;
chip8.loadGame("Games/PONG");
chip8.loadFontset();
// Keymap definition
SDL_Keycode keymap[16] = {
SDLK_x,
SDLK_1,
SDLK_2,
SDLK_3,
SDLK_q,
SDLK_w,
SDLK_e,
SDLK_a,
SDLK_s,
SDLK_d,
SDLK_z,
SDLK_c,
SDLK_4,
SDLK_r,
SDLK_f,
SDLK_v,
};
// SDL Setup
int w = 640;
int h = 320;
SDL_Window *window = NULL;
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
std::cout << "SDL failed to initialize: " << SDL_GetError() << "\n";
exit(1);
}
window = SDL_CreateWindow(
"CHIP-8 Emulator",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
w, h, 0);
if (window == NULL)
{
std::cout << "Failed to create window: " << SDL_GetError() << "\n";
exit(1);
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
SDL_RenderSetLogicalSize(renderer, w, h);
SDL_Texture *sdlTexture = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
64,
32);
uint32_t pixel_buf[2048];
bool quit = false;
while (!quit)
{
chip8.emulateCycle();
if (chip8.drawFlag)
{
chip8.drawFlag = false;
for (int i = 0; i < 2048; i++)
{
pixel_buf[i] = chip8.gfx[i] == 0x0 ? 0xFF000000 : 0xFFFFFFFF;
}
SDL_UpdateTexture(sdlTexture, NULL, pixel_buf, 64 * sizeof(Uint32));
}
SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
quit = true;
}
if (e.type == SDL_KEYDOWN)
{
for (int i = 0; i < 16; i++)
{
if (e.key.keysym.sym == keymap[i])
{
chip8.keyPressed(i);
}
}
}
if (e.type == SDL_KEYUP)
{
for (int i = 0; i < 16; i++)
{
if (e.key.keysym.sym == keymap[i])
{
chip8.keyReleased(i);
}
}
}
}
SDL_RenderCopy(renderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(renderer);
std::this_thread::sleep_for(std::chrono::microseconds(1200));
}
chip8.printState();
return 0;
} | [
"albertboehm@hotmail.de"
] | albertboehm@hotmail.de |
6de016a7eafa8a5422139340e5d0ed54fe2ddbac | a01a63e20eac2335ff9edb4c52ef43de51ac0ad2 | /libcef/browser/net_service/resource_request_handler_wrapper.cc | 0e1983bf83be912b7713aeec2977d565d22c0e8d | [
"BSD-3-Clause"
] | permissive | BruceMann/cef | 96dc35f9b274e733d6466455d241ceb3a782fa65 | 869ae21c9feeb3d9d61bb0f2f8d3e65a2ddd26d0 | refs/heads/master | 2021-05-18T17:37:15.746286 | 2020-03-27T20:00:36 | 2020-03-27T20:22:34 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 45,771 | cc | // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "libcef/browser/net_service/resource_request_handler_wrapper.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net_service/cookie_helper.h"
#include "libcef/browser/net_service/proxy_url_loader_factory.h"
#include "libcef/browser/net_service/resource_handler_wrapper.h"
#include "libcef/browser/net_service/response_filter_wrapper.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/content_client.h"
#include "libcef/common/net/scheme_registration.h"
#include "libcef/common/net_service/net_service_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "chrome/common/chrome_features.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
#include "ui/base/page_transition_types.h"
#include "url/origin.h"
namespace net_service {
namespace {
const int kLoadNoCookiesFlags =
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
class RequestCallbackWrapper : public CefRequestCallback {
public:
using Callback = base::OnceCallback<void(bool /* allow */)>;
explicit RequestCallbackWrapper(Callback callback)
: callback_(std::move(callback)),
work_thread_task_runner_(base::SequencedTaskRunnerHandle::Get()) {}
~RequestCallbackWrapper() override {
if (!callback_.is_null()) {
// Make sure it executes on the correct thread.
work_thread_task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), true));
}
}
void Continue(bool allow) override {
if (!work_thread_task_runner_->RunsTasksInCurrentSequence()) {
work_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&RequestCallbackWrapper::Continue, this, allow));
return;
}
if (!callback_.is_null()) {
std::move(callback_).Run(allow);
}
}
void Cancel() override { Continue(false); }
private:
Callback callback_;
scoped_refptr<base::SequencedTaskRunner> work_thread_task_runner_;
IMPLEMENT_REFCOUNTING(RequestCallbackWrapper);
DISALLOW_COPY_AND_ASSIGN(RequestCallbackWrapper);
};
std::string GetAcceptLanguageList(content::BrowserContext* browser_context,
CefRefPtr<CefBrowserHostImpl> browser) {
if (browser) {
const CefBrowserSettings& browser_settings = browser->settings();
if (browser_settings.accept_language_list.length > 0) {
return CefString(&browser_settings.accept_language_list);
}
}
// This defaults to the value from CefRequestContextSettings via
// browser_prefs::CreatePrefService().
auto prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
return prefs->GetString(language::prefs::kAcceptLanguages);
}
// Match the logic in chrome/browser/net/profile_network_context_service.cc.
std::string ComputeAcceptLanguageFromPref(const std::string& language_pref) {
std::string accept_languages_str =
base::FeatureList::IsEnabled(features::kUseNewAcceptLanguageHeader)
? net::HttpUtil::ExpandLanguageList(language_pref)
: language_pref;
return net::HttpUtil::GenerateAcceptLanguageHeader(accept_languages_str);
}
class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
public:
struct RequestState {
RequestState() {}
void Reset(CefRefPtr<CefResourceRequestHandler> handler,
CefRefPtr<CefSchemeHandlerFactory> scheme_factory,
CefRefPtr<CefRequestImpl> request,
bool request_was_redirected,
CancelRequestCallback cancel_callback) {
handler_ = handler;
scheme_factory_ = scheme_factory;
cookie_filter_ = nullptr;
pending_request_ = request;
pending_response_ = nullptr;
request_was_redirected_ = request_was_redirected;
was_custom_handled_ = false;
cancel_callback_ = std::move(cancel_callback);
}
CefRefPtr<CefResourceRequestHandler> handler_;
CefRefPtr<CefSchemeHandlerFactory> scheme_factory_;
CefRefPtr<CefCookieAccessFilter> cookie_filter_;
CefRefPtr<CefRequestImpl> pending_request_;
CefRefPtr<CefResponseImpl> pending_response_;
bool request_was_redirected_ = false;
bool was_custom_handled_ = false;
CancelRequestCallback cancel_callback_;
};
struct PendingRequest {
PendingRequest(const RequestId& id,
network::ResourceRequest* request,
bool request_was_redirected,
OnBeforeRequestResultCallback callback,
CancelRequestCallback cancel_callback)
: id_(id),
request_(request),
request_was_redirected_(request_was_redirected),
callback_(std::move(callback)),
cancel_callback_(std::move(cancel_callback)) {}
~PendingRequest() {
if (cancel_callback_) {
std::move(cancel_callback_).Run(net::ERR_ABORTED);
}
}
void Run(InterceptedRequestHandlerWrapper* self) {
self->OnBeforeRequest(id_, request_, request_was_redirected_,
std::move(callback_), std::move(cancel_callback_));
}
const RequestId id_;
network::ResourceRequest* const request_;
const bool request_was_redirected_;
OnBeforeRequestResultCallback callback_;
CancelRequestCallback cancel_callback_;
};
// Observer to receive notification of CEF context or associated browser
// destruction. Only one of the *Destroyed() methods will be called.
class DestructionObserver : public CefBrowserHostImpl::Observer,
public CefContext::Observer {
public:
explicit DestructionObserver(CefBrowserHostImpl* browser) {
if (browser) {
browser_info_ = browser->browser_info();
browser->AddObserver(this);
} else {
CefContext::Get()->AddObserver(this);
}
}
virtual ~DestructionObserver() {
CEF_REQUIRE_UIT();
if (!registered_)
return;
// Verify that the browser or context still exists before attempting to
// remove the observer.
if (browser_info_) {
auto browser = browser_info_->browser();
if (browser)
browser->RemoveObserver(this);
} else if (CefContext::Get()) {
// Network requests may be torn down during shutdown, so we can't check
// CONTEXT_STATE_VALID() here.
CefContext::Get()->RemoveObserver(this);
}
}
void SetWrapper(base::WeakPtr<InterceptedRequestHandlerWrapper> wrapper) {
CEF_REQUIRE_IOT();
wrapper_ = wrapper;
}
void OnBrowserDestroyed(CefBrowserHostImpl* browser) override {
CEF_REQUIRE_UIT();
browser->RemoveObserver(this);
registered_ = false;
browser_info_ = nullptr;
NotifyOnDestroyed();
}
void OnContextDestroyed() override {
CEF_REQUIRE_UIT();
CefContext::Get()->RemoveObserver(this);
registered_ = false;
NotifyOnDestroyed();
}
private:
void NotifyOnDestroyed() {
if (wrapper_.MaybeValid()) {
// This will be a no-op if the WeakPtr is invalid.
CEF_POST_TASK(
CEF_IOT,
base::BindOnce(&InterceptedRequestHandlerWrapper::OnDestroyed,
wrapper_));
}
}
scoped_refptr<CefBrowserInfo> browser_info_;
bool registered_ = true;
base::WeakPtr<InterceptedRequestHandlerWrapper> wrapper_;
DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
};
// Holds state information for InterceptedRequestHandlerWrapper. State is
// initialized on the UI thread and later passed to the *Wrapper object on
// the IO thread.
struct InitState {
InitState() {}
~InitState() {
if (destruction_observer_) {
if (initialized_) {
// Clear the reference added in
// InterceptedRequestHandlerWrapper::SetInitialized().
destruction_observer_->SetWrapper(nullptr);
}
DeleteDestructionObserver();
}
}
void Initialize(content::BrowserContext* browser_context,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefFrame> frame,
int render_process_id,
int render_frame_id,
int frame_tree_node_id,
bool is_navigation,
bool is_download,
const url::Origin& request_initiator) {
CEF_REQUIRE_UIT();
browser_context_ = browser_context;
resource_context_ = static_cast<CefResourceContext*>(
browser_context->GetResourceContext());
DCHECK(resource_context_);
// We register to be notified of CEF context or browser destruction so
// that we can stop accepting new requests and cancel pending/in-progress
// requests in a timely manner (e.g. before we start asserting about
// leaked objects during CEF shutdown).
destruction_observer_.reset(new DestructionObserver(browser.get()));
if (browser) {
// These references will be released in OnDestroyed().
browser_ = browser;
frame_ = frame;
}
render_process_id_ = render_process_id;
render_frame_id_ = render_frame_id;
frame_tree_node_id_ = frame_tree_node_id;
is_navigation_ = is_navigation;
is_download_ = is_download;
request_initiator_ = request_initiator.Serialize();
// Default values for standard headers.
accept_language_ = ComputeAcceptLanguageFromPref(
GetAcceptLanguageList(browser_context, browser));
DCHECK(!accept_language_.empty());
user_agent_ = CefContentClient::Get()->browser()->GetUserAgent();
DCHECK(!user_agent_.empty());
}
void DeleteDestructionObserver() {
DCHECK(destruction_observer_);
CEF_POST_TASK(
CEF_UIT,
base::BindOnce(&InitState::DeleteDestructionObserverOnUIThread,
std::move(destruction_observer_)));
}
static void DeleteDestructionObserverOnUIThread(
std::unique_ptr<DestructionObserver> observer) {}
// Only accessed on the UI thread.
content::BrowserContext* browser_context_ = nullptr;
bool initialized_ = false;
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefFrame> frame_;
CefResourceContext* resource_context_ = nullptr;
int render_process_id_ = 0;
int render_frame_id_ = -1;
int frame_tree_node_id_ = -1;
bool is_navigation_ = true;
bool is_download_ = false;
CefString request_initiator_;
// Default values for standard headers.
std::string accept_language_;
std::string user_agent_;
// Used to receive destruction notification.
std::unique_ptr<DestructionObserver> destruction_observer_;
};
// Manages InterceptedRequestHandlerWrapper initialization. The *Wrapper
// object is owned by ProxyURLLoaderFactory and may be deleted before
// SetInitialized() is called.
struct InitHelper : base::RefCountedThreadSafe<InitHelper> {
public:
explicit InitHelper(InterceptedRequestHandlerWrapper* wrapper)
: wrapper_(wrapper) {}
void MaybeSetInitialized(std::unique_ptr<InitState> init_state) {
CEF_POST_TASK(CEF_IOT, base::BindOnce(&InitHelper::SetInitialized, this,
std::move(init_state)));
}
void Disconnect() {
base::AutoLock lock_scope(lock_);
wrapper_ = nullptr;
}
private:
void SetInitialized(std::unique_ptr<InitState> init_state) {
base::AutoLock lock_scope(lock_);
// May be nullptr if the InterceptedRequestHandlerWrapper has already
// been deleted.
if (!wrapper_)
return;
wrapper_->SetInitialized(std::move(init_state));
wrapper_ = nullptr;
}
base::Lock lock_;
InterceptedRequestHandlerWrapper* wrapper_;
};
InterceptedRequestHandlerWrapper()
: init_helper_(base::MakeRefCounted<InitHelper>(this)),
weak_ptr_factory_(this) {}
~InterceptedRequestHandlerWrapper() override {
CEF_REQUIRE_IOT();
// There should be no in-progress requests during destruction.
DCHECK(request_map_.empty());
// Don't continue with initialization if we get deleted before
// SetInitialized is called asynchronously.
init_helper_->Disconnect();
}
scoped_refptr<InitHelper> init_helper() const { return init_helper_; }
void SetInitialized(std::unique_ptr<InitState> init_state) {
CEF_REQUIRE_IOT();
DCHECK(!init_state_);
init_state_ = std::move(init_state);
// Check that the CEF context or associated browser was not destroyed
// between the calls to Initialize and SetInitialized, in which case
// we won't get an OnDestroyed callback from DestructionObserver.
if (init_state_->browser_) {
if (!init_state_->browser_->browser_info()->browser()) {
OnDestroyed();
return;
}
} else if (!CONTEXT_STATE_VALID()) {
OnDestroyed();
return;
}
init_state_->initialized_ = true;
init_state_->destruction_observer_->SetWrapper(
weak_ptr_factory_.GetWeakPtr());
// Continue any pending requests.
if (!pending_requests_.empty()) {
for (const auto& request : pending_requests_)
request->Run(this);
pending_requests_.clear();
}
}
// InterceptedRequestHandler methods:
void OnBeforeRequest(const RequestId& id,
network::ResourceRequest* request,
bool request_was_redirected,
OnBeforeRequestResultCallback callback,
CancelRequestCallback cancel_callback) override {
CEF_REQUIRE_IOT();
if (shutting_down_) {
// Abort immediately.
std::move(cancel_callback).Run(net::ERR_ABORTED);
return;
}
if (!init_state_) {
// Queue requests until we're initialized.
pending_requests_.push_back(std::make_unique<PendingRequest>(
id, request, request_was_redirected, std::move(callback),
std::move(cancel_callback)));
return;
}
// State may already exist for restarted requests.
RequestState* state = GetOrCreateState(id);
// Add standard headers, if currently unspecified.
request->headers.SetHeaderIfMissing(
net::HttpRequestHeaders::kAcceptLanguage,
init_state_->accept_language_);
request->headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
init_state_->user_agent_);
const bool is_external = IsExternalRequest(request);
// External requests will not have a default handler.
bool intercept_only = is_external;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefResourceRequestHandler> handler =
GetHandler(id, request, &intercept_only, requestPtr);
CefRefPtr<CefSchemeHandlerFactory> scheme_factory =
init_state_->resource_context_->GetSchemeHandlerFactory(request->url);
if (scheme_factory && !requestPtr) {
requestPtr = MakeRequest(request, id.hash(), true);
}
// True if there's a possibility that the client might handle the request.
const bool maybe_intercept_request = handler || scheme_factory;
if (!maybe_intercept_request && requestPtr)
requestPtr = nullptr;
// May have a handler and/or scheme factory.
state->Reset(handler, scheme_factory, requestPtr, request_was_redirected,
std::move(cancel_callback));
if (handler) {
state->cookie_filter_ = handler->GetCookieAccessFilter(
init_state_->browser_, init_state_->frame_, requestPtr.get());
}
auto exec_callback =
base::BindOnce(std::move(callback), maybe_intercept_request,
is_external ? true : intercept_only);
if (!maybe_intercept_request) {
// Cookies will be handled by the NetworkService.
std::move(exec_callback).Run();
return;
}
MaybeLoadCookies(id, state, request, std::move(exec_callback));
}
void MaybeLoadCookies(const RequestId& id,
RequestState* state,
network::ResourceRequest* request,
base::OnceClosure callback) {
CEF_REQUIRE_IOT();
// We need to load/save cookies ourselves for custom-handled requests, or
// if we're using a cookie filter.
auto allow_cookie_callback =
state->cookie_filter_
? base::BindRepeating(
&InterceptedRequestHandlerWrapper::AllowCookieLoad,
weak_ptr_factory_.GetWeakPtr(), id)
: base::BindRepeating(
&InterceptedRequestHandlerWrapper::AllowCookieAlways);
auto done_cookie_callback = base::BindOnce(
&InterceptedRequestHandlerWrapper::ContinueWithLoadedCookies,
weak_ptr_factory_.GetWeakPtr(), id, request, std::move(callback));
net_service::LoadCookies(init_state_->browser_context_, *request,
allow_cookie_callback,
std::move(done_cookie_callback));
}
static void AllowCookieAlways(const net::CanonicalCookie& cookie,
bool* allow) {
*allow = true;
}
void AllowCookieLoad(const RequestId& id,
const net::CanonicalCookie& cookie,
bool* allow) {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled while the async callback was
// pending.
return;
}
DCHECK(state->cookie_filter_);
CefCookie cef_cookie;
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
*allow = state->cookie_filter_->CanSendCookie(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), cef_cookie);
}
}
void ContinueWithLoadedCookies(const RequestId& id,
network::ResourceRequest* request,
base::OnceClosure callback,
int total_count,
net::CookieList allowed_cookies) {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled while the async callback was
// pending.
return;
}
if (state->cookie_filter_) {
// Also add/save cookies ourselves for default-handled network requests
// so that we can filter them. This will be a no-op for custom-handled
// requests.
request->load_flags |= kLoadNoCookiesFlags;
}
if (!allowed_cookies.empty()) {
const std::string& cookie_line =
net::CanonicalCookie::BuildCookieLine(allowed_cookies);
request->headers.SetHeader(net::HttpRequestHeaders::kCookie, cookie_line);
state->pending_request_->SetReadOnly(false);
state->pending_request_->SetHeaderByName(net::HttpRequestHeaders::kCookie,
cookie_line, true);
state->pending_request_->SetReadOnly(true);
}
std::move(callback).Run();
}
void ShouldInterceptRequest(
const RequestId& id,
network::ResourceRequest* request,
ShouldInterceptRequestResultCallback callback) override {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled during destruction.
return;
}
// Must have a handler and/or scheme factory.
DCHECK(state->handler_ || state->scheme_factory_);
DCHECK(state->pending_request_);
if (state->handler_) {
// The client may modify |pending_request_| before executing the callback.
state->pending_request_->SetReadOnly(false);
state->pending_request_->SetTrackChanges(true,
true /* backup_on_change */);
CefRefPtr<RequestCallbackWrapper> callbackPtr =
new RequestCallbackWrapper(base::BindOnce(
&InterceptedRequestHandlerWrapper::ContinueShouldInterceptRequest,
weak_ptr_factory_.GetWeakPtr(), id, base::Unretained(request),
std::move(callback)));
cef_return_value_t retval = state->handler_->OnBeforeResourceLoad(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), callbackPtr.get());
if (retval != RV_CONTINUE_ASYNC) {
// Continue or cancel the request immediately.
callbackPtr->Continue(retval == RV_CONTINUE);
}
} else {
// The scheme factory may choose to handle it.
ContinueShouldInterceptRequest(id, request, std::move(callback), true);
}
}
void ContinueShouldInterceptRequest(
const RequestId& id,
network::ResourceRequest* request,
ShouldInterceptRequestResultCallback callback,
bool allow) {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled while the async callback was
// pending.
return;
}
// Must have a handler and/or scheme factory.
DCHECK(state->handler_ || state->scheme_factory_);
DCHECK(state->pending_request_);
if (state->handler_) {
if (allow) {
// Apply any |requestPtr| changes to |request|.
state->pending_request_->Get(request, true /* changed_only */);
}
const bool redirect =
(state->pending_request_->GetChanges() & CefRequestImpl::kChangedUrl);
if (redirect) {
// Revert any changes for now. We'll get them back after the redirect.
state->pending_request_->RevertChanges();
}
state->pending_request_->SetReadOnly(true);
state->pending_request_->SetTrackChanges(false);
if (!allow) {
// Cancel the request.
if (state->cancel_callback_) {
std::move(state->cancel_callback_).Run(net::ERR_ABORTED);
}
return;
}
if (redirect) {
// Performing a redirect.
std::move(callback).Run(nullptr);
return;
}
}
CefRefPtr<CefResourceHandler> resource_handler;
if (state->handler_) {
// Does the client want to handle the request?
resource_handler = state->handler_->GetResourceHandler(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get());
}
if (!resource_handler && state->scheme_factory_) {
// Does the scheme factory want to handle the request?
resource_handler = state->scheme_factory_->Create(
init_state_->browser_, init_state_->frame_, request->url.scheme(),
state->pending_request_.get());
}
std::unique_ptr<ResourceResponse> resource_response;
if (resource_handler) {
resource_response = CreateResourceResponse(id, resource_handler);
DCHECK(resource_response);
state->was_custom_handled_ = true;
} else {
// The request will be handled by the NetworkService. Remove the
// "Accept-Language" header here so that it can be re-added in
// URLRequestHttpJob::AddExtraHeaders with correct ordering applied.
request->headers.RemoveHeader(net::HttpRequestHeaders::kAcceptLanguage);
}
// Continue the request.
std::move(callback).Run(std::move(resource_response));
}
void ProcessResponseHeaders(const RequestId& id,
const network::ResourceRequest& request,
const GURL& redirect_url,
net::HttpResponseHeaders* headers) override {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled during destruction.
return;
}
if (!state->handler_)
return;
if (!state->pending_response_)
state->pending_response_ = new CefResponseImpl();
else
state->pending_response_->SetReadOnly(false);
if (headers)
state->pending_response_->SetResponseHeaders(*headers);
state->pending_response_->SetReadOnly(true);
}
void OnRequestResponse(const RequestId& id,
network::ResourceRequest* request,
net::HttpResponseHeaders* headers,
base::Optional<net::RedirectInfo> redirect_info,
OnRequestResponseResultCallback callback) override {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled during destruction.
return;
}
if (state->cookie_filter_) {
// Remove the flags that were added in ContinueWithLoadedCookies.
request->load_flags &= ~kLoadNoCookiesFlags;
}
if (!state->handler_) {
// Cookies may come from a scheme handler.
MaybeSaveCookies(
id, state, request, headers,
base::BindOnce(
std::move(callback), ResponseMode::CONTINUE, nullptr,
redirect_info.has_value() ? redirect_info->new_url : GURL()));
return;
}
DCHECK(state->pending_request_);
DCHECK(state->pending_response_);
if (redirect_info.has_value()) {
HandleRedirect(id, state, request, headers, *redirect_info,
std::move(callback));
} else {
HandleResponse(id, state, request, headers, std::move(callback));
}
}
void HandleRedirect(const RequestId& id,
RequestState* state,
network::ResourceRequest* request,
net::HttpResponseHeaders* headers,
const net::RedirectInfo& redirect_info,
OnRequestResponseResultCallback callback) {
GURL new_url = redirect_info.new_url;
CefString newUrl = redirect_info.new_url.spec();
CefString oldUrl = newUrl;
bool url_changed = false;
state->handler_->OnResourceRedirect(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), state->pending_response_.get(), newUrl);
if (newUrl != oldUrl) {
// Also support relative URLs.
const GURL& url = redirect_info.new_url.Resolve(newUrl.ToString());
if (url.is_valid()) {
url_changed = true;
new_url = url;
}
}
// Update the |pending_request_| object with the new info.
state->pending_request_->SetReadOnly(false);
state->pending_request_->Set(redirect_info);
if (url_changed) {
state->pending_request_->SetURL(new_url.spec());
}
state->pending_request_->SetReadOnly(true);
auto exec_callback = base::BindOnce(
std::move(callback), ResponseMode::CONTINUE, nullptr, new_url);
MaybeSaveCookies(id, state, request, headers, std::move(exec_callback));
}
void HandleResponse(const RequestId& id,
RequestState* state,
network::ResourceRequest* request,
net::HttpResponseHeaders* headers,
OnRequestResponseResultCallback callback) {
// The client may modify |pending_request_| in OnResourceResponse.
state->pending_request_->SetReadOnly(false);
state->pending_request_->SetTrackChanges(true, true /* backup_on_change */);
auto response_mode = ResponseMode::CONTINUE;
GURL new_url;
if (state->handler_->OnResourceResponse(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), state->pending_response_.get())) {
// The request may have been modified.
const auto changes = state->pending_request_->GetChanges();
if (changes) {
state->pending_request_->Get(request, true /* changed_only */);
if (changes & CefRequestImpl::kChangedUrl) {
// Redirect to the new URL.
new_url = GURL(state->pending_request_->GetURL().ToString());
} else {
// Restart the request.
response_mode = ResponseMode::RESTART;
}
}
}
// Revert any changes for now. We'll get them back after the redirect or
// restart.
state->pending_request_->RevertChanges();
state->pending_request_->SetReadOnly(true);
state->pending_request_->SetTrackChanges(false);
auto exec_callback =
base::BindOnce(std::move(callback), response_mode, nullptr, new_url);
if (response_mode == ResponseMode::RESTART) {
// Get any cookies after the restart.
std::move(exec_callback).Run();
return;
}
MaybeSaveCookies(id, state, request, headers, std::move(exec_callback));
}
void MaybeSaveCookies(const RequestId& id,
RequestState* state,
network::ResourceRequest* request,
net::HttpResponseHeaders* headers,
base::OnceClosure callback) {
CEF_REQUIRE_IOT();
if (!state->cookie_filter_ && !state->was_custom_handled_) {
// The NetworkService saves the cookies for default-handled requests.
std::move(callback).Run();
return;
}
// We need to load/save cookies ourselves for custom-handled requests, or
// if we're using a cookie filter.
auto allow_cookie_callback =
state->cookie_filter_
? base::BindRepeating(
&InterceptedRequestHandlerWrapper::AllowCookieSave,
weak_ptr_factory_.GetWeakPtr(), id)
: base::BindRepeating(
&InterceptedRequestHandlerWrapper::AllowCookieAlways);
auto done_cookie_callback = base::BindOnce(
&InterceptedRequestHandlerWrapper::ContinueWithSavedCookies,
weak_ptr_factory_.GetWeakPtr(), id, std::move(callback));
net_service::SaveCookies(init_state_->browser_context_, *request, headers,
allow_cookie_callback,
std::move(done_cookie_callback));
}
void AllowCookieSave(const RequestId& id,
const net::CanonicalCookie& cookie,
bool* allow) {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled while the async callback was
// pending.
return;
}
DCHECK(state->cookie_filter_);
CefCookie cef_cookie;
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
*allow = state->cookie_filter_->CanSaveCookie(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), state->pending_response_.get(),
cef_cookie);
}
}
void ContinueWithSavedCookies(const RequestId& id,
base::OnceClosure callback,
int total_count,
net::CookieList allowed_cookies) {
CEF_REQUIRE_IOT();
std::move(callback).Run();
}
mojo::ScopedDataPipeConsumerHandle OnFilterResponseBody(
const RequestId& id,
const network::ResourceRequest& request,
mojo::ScopedDataPipeConsumerHandle body) override {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled during destruction.
return body;
}
if (state->handler_) {
auto filter = state->handler_->GetResourceResponseFilter(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), state->pending_response_.get());
if (filter) {
return CreateResponseFilterHandler(
filter, std::move(body),
base::BindOnce(&InterceptedRequestHandlerWrapper::OnFilterError,
weak_ptr_factory_.GetWeakPtr(), id));
}
}
return body;
}
void OnFilterError(const RequestId& id) {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been canceled while the async callback was
// pending.
return;
}
if (state->cancel_callback_) {
std::move(state->cancel_callback_).Run(net::ERR_CONTENT_DECODING_FAILED);
}
}
void OnRequestComplete(
const RequestId& id,
const network::ResourceRequest& request,
const network::URLLoaderCompletionStatus& status) override {
CEF_REQUIRE_IOT();
RequestState* state = GetState(id);
if (!state) {
// The request may have been aborted during initialization or canceled
// during destruction. This method will always be called before a request
// is deleted, so if the request is currently pending also remove it from
// the list.
if (!pending_requests_.empty()) {
PendingRequests::iterator it = pending_requests_.begin();
for (; it != pending_requests_.end(); ++it) {
if ((*it)->id_ == id) {
pending_requests_.erase(it);
break;
}
}
}
return;
}
const bool is_external = IsExternalRequest(&request);
// Redirection of standard custom schemes is handled with a restart, so we
// get completion notifications for both the original (redirected) request
// and the final request. Don't report completion of the redirected request.
const bool ignore_result = is_external && request.url.IsStandard() &&
status.error_code == net::ERR_ABORTED &&
state->pending_response_.get() &&
net::HttpResponseHeaders::IsRedirectResponseCode(
state->pending_response_->GetStatus());
if (state->handler_ && !ignore_result) {
DCHECK(state->pending_request_);
CallHandlerOnComplete(state, status);
if (status.error_code != 0 && is_external) {
bool allow_os_execution = false;
state->handler_->OnProtocolExecution(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), allow_os_execution);
if (allow_os_execution) {
CefBrowserPlatformDelegate::HandleExternalProtocol(request.url);
}
}
}
RemoveState(id);
}
private:
void CallHandlerOnComplete(RequestState* state,
const network::URLLoaderCompletionStatus& status) {
if (!state->handler_ || !state->pending_request_)
return;
// The request object may be currently flagged as writable in cases where we
// abort a request that is waiting on a pending callack.
if (!state->pending_request_->IsReadOnly()) {
state->pending_request_->SetReadOnly(true);
}
if (!state->pending_response_) {
// If the request failed there may not be a response object yet.
state->pending_response_ = new CefResponseImpl();
} else {
state->pending_response_->SetReadOnly(false);
}
state->pending_response_->SetError(
static_cast<cef_errorcode_t>(status.error_code));
state->pending_response_->SetReadOnly(true);
state->handler_->OnResourceLoadComplete(
init_state_->browser_, init_state_->frame_,
state->pending_request_.get(), state->pending_response_.get(),
status.error_code == 0 ? UR_SUCCESS : UR_FAILED,
status.encoded_body_length);
}
// Returns the handler, if any, that should be used for this request.
CefRefPtr<CefResourceRequestHandler> GetHandler(
const RequestId& id,
network::ResourceRequest* request,
bool* intercept_only,
CefRefPtr<CefRequestImpl>& requestPtr) const {
CefRefPtr<CefResourceRequestHandler> handler;
const int64 request_id = id.hash();
if (init_state_->browser_) {
// Maybe the browser's client wants to handle it?
CefRefPtr<CefClient> client =
init_state_->browser_->GetHost()->GetClient();
if (client) {
CefRefPtr<CefRequestHandler> request_handler =
client->GetRequestHandler();
if (request_handler) {
requestPtr = MakeRequest(request, request_id, true);
handler = request_handler->GetResourceRequestHandler(
init_state_->browser_, init_state_->frame_, requestPtr.get(),
init_state_->is_navigation_, init_state_->is_download_,
init_state_->request_initiator_, *intercept_only);
}
}
}
if (!handler) {
// Maybe the request context wants to handle it?
CefRefPtr<CefRequestContextHandler> context_handler =
init_state_->resource_context_->GetHandler(
init_state_->render_process_id_, request->render_frame_id,
init_state_->frame_tree_node_id_, false);
if (context_handler) {
if (!requestPtr)
requestPtr = MakeRequest(request, request_id, true);
handler = context_handler->GetResourceRequestHandler(
init_state_->browser_, init_state_->frame_, requestPtr.get(),
init_state_->is_navigation_, init_state_->is_download_,
init_state_->request_initiator_, *intercept_only);
}
}
return handler;
}
RequestState* GetOrCreateState(const RequestId& id) {
RequestState* state = GetState(id);
if (!state) {
state = new RequestState();
request_map_.insert(std::make_pair(id, base::WrapUnique(state)));
}
return state;
}
RequestState* GetState(const RequestId& id) const {
RequestMap::const_iterator it = request_map_.find(id);
if (it != request_map_.end())
return it->second.get();
return nullptr;
}
void RemoveState(const RequestId& id) {
RequestMap::iterator it = request_map_.find(id);
DCHECK(it != request_map_.end());
if (it != request_map_.end())
request_map_.erase(it);
}
// Stop accepting new requests and cancel pending/in-flight requests when the
// CEF context or associated browser is destroyed.
void OnDestroyed() {
CEF_REQUIRE_IOT();
DCHECK(init_state_);
init_state_->DeleteDestructionObserver();
// Stop accepting new requests.
shutting_down_ = true;
// Stop the delivery of pending callbacks.
weak_ptr_factory_.InvalidateWeakPtrs();
// Take ownership of any pending requests.
PendingRequests pending_requests;
pending_requests.swap(pending_requests_);
// Take ownership of any in-progress requests.
RequestMap request_map;
request_map.swap(request_map_);
// Notify handlers for in-progress requests.
for (const auto& pair : request_map) {
CallHandlerOnComplete(
pair.second.get(),
network::URLLoaderCompletionStatus(net::ERR_ABORTED));
}
if (init_state_->browser_) {
// Clear objects that reference the browser.
init_state_->browser_ = nullptr;
init_state_->frame_ = nullptr;
}
// Execute cancel callbacks and delete pending and in-progress requests.
// This may result in the request being torn down sooner, or it may be
// ignored if the request is already in the process of being torn down. When
// the last callback is executed it may result in |this| being deleted.
pending_requests.clear();
for (auto& pair : request_map) {
auto state = std::move(pair.second);
if (state->cancel_callback_) {
std::move(state->cancel_callback_).Run(net::ERR_ABORTED);
}
}
}
static CefRefPtr<CefRequestImpl> MakeRequest(
const network::ResourceRequest* request,
int64 request_id,
bool read_only) {
CefRefPtr<CefRequestImpl> requestPtr = new CefRequestImpl();
requestPtr->Set(request, request_id);
if (read_only)
requestPtr->SetReadOnly(true);
else
requestPtr->SetTrackChanges(true);
return requestPtr;
}
// Returns true if |request| cannot be handled internally.
static bool IsExternalRequest(const network::ResourceRequest* request) {
return !scheme::IsInternalHandledScheme(request->url.scheme());
}
scoped_refptr<InitHelper> init_helper_;
std::unique_ptr<InitState> init_state_;
bool shutting_down_ = false;
using RequestMap = std::map<RequestId, std::unique_ptr<RequestState>>;
RequestMap request_map_;
using PendingRequests = std::vector<std::unique_ptr<PendingRequest>>;
PendingRequests pending_requests_;
base::WeakPtrFactory<InterceptedRequestHandlerWrapper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(InterceptedRequestHandlerWrapper);
};
void InitOnUIThread(
scoped_refptr<InterceptedRequestHandlerWrapper::InitHelper> init_helper,
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
const network::ResourceRequest& request) {
CEF_REQUIRE_UIT();
// May return nullptr if the WebContents was destroyed while this callback was
// in-flight.
content::WebContents* web_contents = web_contents_getter.Run();
if (!web_contents) {
return;
}
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
DCHECK(browser_context);
const int render_process_id =
web_contents->GetRenderViewHost()->GetProcess()->GetID();
content::RenderFrameHost* frame = nullptr;
if (request.render_frame_id >= 0) {
// TODO(network): Are these main frame checks equivalent?
if (request.is_main_frame ||
static_cast<content::ResourceType>(request.resource_type) ==
content::ResourceType::kMainFrame) {
frame = web_contents->GetMainFrame();
DCHECK(frame);
} else {
// May return null for newly created iframes.
frame = content::RenderFrameHost::FromID(render_process_id,
request.render_frame_id);
if (!frame && frame_tree_node_id >= 0) {
// May return null for frames in inner WebContents.
frame = web_contents->FindFrameByFrameTreeNodeId(frame_tree_node_id,
render_process_id);
}
if (!frame) {
// Use the main frame for the CefBrowserHost.
frame = web_contents->GetMainFrame();
DCHECK(frame);
}
}
}
CefRefPtr<CefBrowserHostImpl> browserPtr;
CefRefPtr<CefFrame> framePtr;
// |frame| may be null for service worker requests.
if (frame) {
// May return nullptr for requests originating from guest views.
browserPtr = CefBrowserHostImpl::GetBrowserForHost(frame);
if (browserPtr) {
framePtr = browserPtr->GetFrameForHost(frame);
if (frame_tree_node_id < 0)
frame_tree_node_id = frame->GetFrameTreeNodeId();
DCHECK(framePtr);
}
}
const bool is_navigation = ui::PageTransitionIsNewNavigation(
static_cast<ui::PageTransition>(request.transition_type));
// TODO(navigation): Can we determine the |is_download| value?
const bool is_download = false;
url::Origin request_initiator;
if (request.request_initiator.has_value())
request_initiator = *request.request_initiator;
auto init_state =
std::make_unique<InterceptedRequestHandlerWrapper::InitState>();
init_state->Initialize(browser_context, browserPtr, framePtr,
render_process_id, request.render_frame_id,
frame_tree_node_id, is_navigation, is_download,
request_initiator);
init_helper->MaybeSetInitialized(std::move(init_state));
}
} // namespace
std::unique_ptr<InterceptedRequestHandler> CreateInterceptedRequestHandler(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
int render_process_id,
bool is_navigation,
bool is_download,
const url::Origin& request_initiator) {
CEF_REQUIRE_UIT();
CefRefPtr<CefBrowserHostImpl> browserPtr;
CefRefPtr<CefFrame> framePtr;
int render_frame_id = -1;
int frame_tree_node_id = -1;
// |frame| may be null for service worker requests.
if (frame) {
render_frame_id = frame->GetRoutingID();
frame_tree_node_id = frame->GetFrameTreeNodeId();
// May return nullptr for requests originating from guest views.
browserPtr = CefBrowserHostImpl::GetBrowserForHost(frame);
if (browserPtr) {
framePtr = browserPtr->GetFrameForHost(frame);
DCHECK(framePtr);
}
}
auto init_state =
std::make_unique<InterceptedRequestHandlerWrapper::InitState>();
init_state->Initialize(browser_context, browserPtr, framePtr,
render_process_id, render_frame_id, frame_tree_node_id,
is_navigation, is_download, request_initiator);
auto wrapper = std::make_unique<InterceptedRequestHandlerWrapper>();
wrapper->init_helper()->MaybeSetInitialized(std::move(init_state));
return wrapper;
}
std::unique_ptr<InterceptedRequestHandler> CreateInterceptedRequestHandler(
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
const network::ResourceRequest& request) {
auto wrapper = std::make_unique<InterceptedRequestHandlerWrapper>();
CEF_POST_TASK(CEF_UIT, base::BindOnce(InitOnUIThread, wrapper->init_helper(),
web_contents_getter, frame_tree_node_id,
request));
return wrapper;
}
} // namespace net_service
| [
"magreenblatt@gmail.com"
] | magreenblatt@gmail.com |
f5422f9290747d1f3d3209c07a52848bb2105d76 | 55fe788d2a4bbc24c945e257a55f6d83d77ee5c9 | /Chef and Destruction.cpp | e2342639e11e28deefe0dca32478f72813af7c0e | [] | no_license | magnus390/first_project | 2fbf37ac5a92b23be1185bff10dffaa3a55e7e15 | 7ac5ed688e5a946d9fa8d9f4c12837d899ec5993 | refs/heads/master | 2020-03-21T10:51:00.354234 | 2018-06-24T11:27:16 | 2018-06-24T11:27:16 | 138,474,484 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 365 | cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n;
cin>>t;
while(t--)
{
map <long long int, long long int> m;
long long ans = INT_MIN;
cin>>n;
int temp;
for(int i=0;i<n;i++)
{
cin>>temp;
m[temp]++;
ans = max(ans,m[temp]);
}
if(ans>(n+1)/2)
cout<<ans<<endl;
else
cout<<(n+1)/2<<endl;
}
}
| [
"noreply@github.com"
] | noreply@github.com |
a52900740f8ba85d73db02d444a90a2c1373befb | 155c4955c117f0a37bb9481cd1456b392d0e9a77 | /core/XMLObject.cpp | a0517f43479bc55d7f2c3c3bea4ba23a654ba4b9 | [] | no_license | zwetan/tessa | 605720899aa2eb4207632700abe7e2ca157d19e6 | 940404b580054c47f3ced7cf8995794901cf0aaa | refs/heads/master | 2021-01-19T19:54:00.236268 | 2011-08-31T00:18:24 | 2011-08-31T00:18:24 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 97,628 | cpp | /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is [Open Source Virtual Machine.].
*
* The Initial Developer of the Original Code is
* Adobe System Incorporated.
* Portions created by the Initial Developer are Copyright (C) 2004-2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adobe AS3 Team
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/////////////////////////////////////////////////////////
// Internal properties of the E4XNode classes
// Multiname *m_name;
// Stringp m_value;
// E4XNode *m_parent; // the parent or NULL for top item
// AtomArray *m_attributes;
// AtomArray *m_namespaces;
// AtomArray *m_children;
//
// kAttribute (AttributeE4XNode)
// m_name = Multiname containing namespace:name pair (marked as an attribute)
// m_value = text value of the attribute
// kText/kCDATA (TextE4XNode, CDATAE4XNode)
// m_value - text value of the node
// kComment (CommentE4XNode)
// m_value - text value of the node
// kProcessingInstruction (PIE4XNode)
// m_name = Multiname containing namespace:name pair
// m_value - text value of the node
// kElement (ElementE4XNode)
// m_name = Multiname containing namespace:name pair
// m_attributes : list of attributes (E4XNodes's)
// m_children : array of children nodes (E4XNodes's) or
// m_namespaces: array of namespaces for this node
//
// QName contains a Multiname with only ONE namespace
// null
// "" empty string
// uri
//
// Properties of the XML object can be either qualified (one associated namespace)
// or unqualified.
//
// Property access to the XML object can be a variety of cases:
// qualified: one namespace
// unqualified: one or more namespaces (the public namespace, plus others)
// anyName operator - matches both qualified and unqualified properties
#include "avmplus.h"
#include "BuiltinNatives.h"
//#define STRING_DEBUG
namespace avmplus
{
XMLObject::XMLObject(XMLClass *type, E4XNode *node)
: ScriptObject(type->ivtable(), type->prototypePtr()), m_node(node)
{
SAMPLE_FRAME("XML", this->core());
this->publicNS = core()->findPublicNamespace();
}
// This is considered the "toXML function"
XMLObject::XMLObject(XMLClass *type, Stringp str, Namespace *defaultNamespace)
: ScriptObject(type->ivtable(), type->prototypePtr())
{
SAMPLE_FRAME("XML", this->core());
#if 0//def _DEBUG
// *** NOTE ON THREAD SAFETY ***
//
// Enabling this code means that there may be a race to initialize 'once' on different
// threads, or, alternatively, that only one core gets to run this code, not each core
// individually. This may or may not be OK, but needs to be considered before enabling
// the code.
static bool once = false;
if (!once)
{
once = true;
AvmDebugMsg(false, "sizeof(E4XNode): %d\r\n", sizeof(E4XNode));
AvmDebugMsg(false, "sizeof(TextE4XNode): %d\r\n", sizeof(TextE4XNode));
AvmDebugMsg(false, "sizeof(ElementE4XNode): %d\r\n", sizeof(ElementE4XNode));
AvmDebugMsg(false, "sizeof(E4XNodeAux): %d\r\n", sizeof(E4XNodeAux));
}
#endif
if (!str)
return;
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
MMgc::GC *gc = core->GetGC();
this->publicNS = core->findPublicNamespace();
AvmAssert(traits()->getSizeOfInstance() == sizeof(XMLObject));
AvmAssert(traits()->getExtraSize() == 0);
// str, ignoreWhite
bool bIgnoreWhite = toplevel->xmlClass()->get_ignoreWhitespace() != 0;
XMLParser parser(core, str);
parser.parse(bIgnoreWhite);
parser.setCondenseWhite(true);
XMLTag tag(gc);
E4XNode* p = 0;
// When we're passed in a defaultNamespace, we simulate the following XML code
// <parent xmlns=defaultNamespace's URI>string</parent>
if (defaultNamespace)
{
setNode( new (gc) ElementE4XNode (0) );
// create a namespace for the parent using defaultNamespace->URI()
Namespace *ns = core->internNamespace (core->newNamespace (core->kEmptyString->atom(), defaultNamespace->getURI()->atom()));
m_node->_addInScopeNamespace (core, ns, publicNS);
Stringp name = core->internConstantStringLatin1("parent");
m_node->setQName (core, name, ns);
p = m_node;
}
int m_status;
while ((m_status = parser.getNext(tag)) == XMLParser::kNoError)
{
E4XNode* pNewElement = NULL;
switch (tag.nodeType)
{
case XMLTag::kXMLDeclaration:
{
// !!@ add some checks to ensure this is the first tag
// encountered in our file (deal with <parent> stuff from
// XMLObject and XMLListObject parser setup
}
break;
case XMLTag::kDocTypeDeclaration:
break;
case XMLTag::kElementType:
{
// A closing tag
if (tag.text->charAt(0) == '/')
{
const int32_t nodeNameStart = 1; // skip the slash
Multiname m;
p->getQName(&m, publicNS);
Namespace* ns = m.getNamespace();
// Get our parent's qualified name string here
Stringp parentName = m.getName();
if (!NodeNameEquals(tag.text, nodeNameStart, parentName, ns) &&
// We're trying to support paired nodes where the first node gets a namespace
// from the default namespace.
parentName->Compare(*tag.text, nodeNameStart, tag.text->length()-nodeNameStart) != 0 &&
ns->getURI() == toplevel->getDefaultNamespace()->getURI())
{
// If p == m_node, we are at the top of our tree and we're parsing the fake "parent"
// wrapper tags around our actual XML text. Instead of warning about a missing "</parent>"
// tag, we instead complain about the XML markup not being well-formed.
// (Emulating Rhino behavior)
if (p == m_node)
toplevel->throwTypeError(kXMLMarkupMustBeWellFormed);
else
toplevel->throwTypeError(kXMLUnterminatedElementTag, parentName, parentName);
}
else
{
// Catch the case where our input string ends with a bogus <parent> tag
if (defaultNamespace && (p == m_node))
toplevel->throwTypeError(kXMLMarkupMustBeWellFormed);
// found matching closing tag so we can pop back up a level now
if (p != m_node)
p = p->getParent();
}
}
else // an opening tag
{
ElementE4XNode *e = new (gc) ElementE4XNode(0);
pNewElement = e;
// Our first tag modifies this object itself
if (!m_node)
{
setNode(pNewElement);
}
else // all other tags create a new element tag
{
p->_append(pNewElement);
}
if (!tag.empty) // if our tag is not empty, we're now the "parent" tag
{
p = pNewElement;
}
// Needs to happen after setting m_name->name so throw error can use name in routine
e->CopyAttributesAndNamespaces(core, toplevel, tag, publicNS);
// Find a namespace that matches this tag in our parent chain. If this name
// is a qualified name (ns:name), we search for a namespace with a matching
// prefix. If is an unqualified name, we find the first empty prefix name.
Namespace *ns = pNewElement->FindNamespace(core, toplevel, tag.text, false);
// pg 35, map [[name]].uri to "namespace name" of node
if (!ns) {
// NOTE use caller's public
ns = core->findPublicNamespace();
}
pNewElement->setQName(core, tag.text, ns);
}
}
break;
case XMLTag::kComment:
if (!toplevel->xmlClass()->get_ignoreComments())
{
pNewElement = new (gc) CommentE4XNode (0, tag.text);
if (!m_node)
setNode( pNewElement );
}
break;
case XMLTag::kCDataSection:
pNewElement = new (gc) CDATAE4XNode (0, tag.text);
if (!m_node)
setNode( pNewElement );
break;
case XMLTag::kTextNodeType:
// For small strings, we intern them in an attempt to save memory
// with large XML files with of lot of repeating text nodes.
if (tag.text->length() < 32)
{
Stringp text = core->internString(tag.text);
// Reduce our GC pressure if we know our tag.text is unused.
if (text != tag.text)
{
AvmAssert(!tag.text->isInterned());
tag.text = NULL;
}
pNewElement = new (gc) TextE4XNode(0, text);
}
else
{
pNewElement = new (gc) TextE4XNode(0, tag.text);
}
if (!m_node)
setNode( pNewElement );
break;
case XMLTag::kProcessingInstruction:
if (!toplevel->xmlClass()->get_ignoreProcessingInstructions())
{
Stringp name, val;
int32_t space = tag.text->indexOfLatin1(" ", 1, 0);
if (space < 0)
{
// no spaces, no value
name = tag.text;
val = core->kEmptyString;
}
else
{
name = tag.text->substring(0, space);
while (String::isSpace((wchar) tag.text->charAt(++space))) {}
val = tag.text->substring(space, tag.text->length());
}
pNewElement = new (gc) PIE4XNode(0, val);
// NOTE use caller's public
pNewElement->setQName (core, name, core->findPublicNamespace());
if (!m_node)
setNode( pNewElement );
}
break;
//kNoType = 0,
default:
AvmAssert(0); // unknown tag type??
}
if ( pNewElement && (XMLTag::kElementType != tag.nodeType))
{
if (pNewElement != m_node)
p->_append( pNewElement);
}
if ( m_status != XMLParser::kNoError )
{
break; // stop getting tags
}
}
if ( m_status == XMLParser::kEndOfDocument )
{
m_status = XMLParser::kNoError;
}
else
{
switch (m_status)
{
case XMLParser::kMalformedElement:
toplevel->throwTypeError(kXMLMalformedElement);
break;
case XMLParser::kUnterminatedCDataSection:
toplevel->throwTypeError(kXMLUnterminatedCData);
break;
case XMLParser::kUnterminatedXMLDeclaration:
toplevel->throwTypeError(kXMLUnterminatedXMLDecl);
break;
case XMLParser::kUnterminatedDocTypeDeclaration:
toplevel->throwTypeError(kXMLUnterminatedDocTypeDecl);
break;
case XMLParser::kUnterminatedComment:
toplevel->throwTypeError(kXMLUnterminatedComment);
break;
case XMLParser::kUnterminatedAttributeValue:
toplevel->throwTypeError(kXMLUnterminatedAttribute);
break;
case XMLParser::kUnterminatedElement:
toplevel->throwTypeError(kXMLUnterminatedElement);
break;
case XMLParser::kUnterminatedProcessingInstruction:
toplevel->throwTypeError(kXMLUnterminatedProcessingInstruction);
break;
case XMLParser::kOutOfMemory:
case XMLParser::kElementNeverBegun:
AvmAssert(0);
break;
}
}
if ( p != m_node && ! m_status )
{
Multiname m;
p->getQName(&m, publicNS);
// Get our parents qualified name string here
Stringp parentName = m.getName();
toplevel->throwTypeError(kXMLUnterminatedElementTag, parentName, parentName);
}
}
bool XMLObject::NodeNameEquals(Stringp nodeName, int32_t nodeNameStart, Stringp parentName, Namespace * parentNs)
{
int32_t const nodeNameLength = nodeName->length() - nodeNameStart;
if (parentNs && parentNs->hasPrefix())
{
AvmCore *core = this->core();
Stringp parentNSName = core->string(parentNs->getPrefix());
int prefixLen = parentNSName->length();
// Does nodeName == parentNS:parentName
int totalLen = prefixLen + 1 + parentName->length(); // + 1 for ':' separator
if (totalLen != nodeNameLength)
return false;
if (parentNSName->Compare(*nodeName, nodeNameStart, prefixLen) != 0)
return false;
if (nodeName->charAt(nodeNameStart + prefixLen) != ':')
return false;
// -1 for ':'
prefixLen++;
return (parentName->Compare(*nodeName, nodeNameStart + prefixLen, nodeNameLength - prefixLen) == 0);
}
else
{
return parentName->Compare(*nodeName, nodeNameStart, nodeNameLength) == 0;
}
}
//////////////////////////////////////////////////////////////////////
// E4X Section 9.1.1
//////////////////////////////////////////////////////////////////////
// sec 11.2.2.1 CallMethod
// this = argv[0] (ignored)
// arg1 = argv[1]
// argN = argv[argc]
Atom XMLObject::callProperty(const Multiname* multiname, int argc, Atom* argv)
{
AvmCore *core = this->core();
Atom f = getDelegate()->getMultinameProperty(multiname);
if (f == undefinedAtom)
{
f = getMultinameProperty(multiname);
// If our method returned is a 0 element XMLList, it means that we did not
// find a matching property for this method name. In this case, if our XML
// node is simple, we convert it to a string and callproperty on the string.
// This allows node elements to be treated as simple strings even if they
// are XML or XMLList objects. See 11.2.2.1 in the E4X spec for CallMethod.
if (AvmCore::isXMLList(f) &&
!AvmCore::atomToXMLList(f)->_length() &&
(hasSimpleContent()))
{
Stringp r0 = core->string (this->atom());
return toplevel()->callproperty (r0->atom(), multiname, argc, argv, toplevel()->stringClass->vtable);
}
}
argv[0] = atom(); // replace receiver
return toplevel()->op_call(f, argc, argv);
}
// E4X 9.1.1.1, pg 12 - [[GET]]
Atom XMLObject::getAtomProperty(Atom P) const
{
Multiname m;
toplevel()->ToXMLName(P, m);
return getMultinameProperty(&m);
}
// E4X 9.1.1.1, pg 12 - [[GET]]
Atom XMLObject::getMultinameProperty(const Multiname* name_in) const
{
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
Multiname name;
toplevel->CoerceE4XMultiname(name_in, name);
#ifdef STRING_DEBUG
Stringp n1 = name.getName();
#endif
if (!name.isAnyName() && !name.isAttr())
{
// We have an integer argument - direct child lookup
Stringp nameString = name.getName();
uint32 index;
if (AvmCore::getIndexFromString (nameString, &index))
{
// //l = ToXMLList (this);
// //return l->get(p);
// ToXMLList on a XMLNode just creates a one item XMLList. The only valid
// property number for the new XMLList is 0 which just returns this node. Handle
// that case here.
if (index == 0)
return this->atom();
else
return undefinedAtom;
}
}
XMLListObject *xl = new (core->GetGC()) XMLListObject(toplevel->xmlListClass(), this->atom(), &name);
if (name.isAttr())
{
// does not hurt, but makes things faster
xl->checkCapacity(m_node->numAttributes());
// for each a in x.[[attributes]]
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
E4XNode *xml = m_node->getAttribute(i);
AvmAssert(xml && xml->getClass() == E4XNode::kAttribute);
Multiname m;
AvmAssert(xml->getQName(&m, publicNS) != 0);
//if (((n.[[Name]].localName == "*") || (n.[[Name]].localName == a.[[Name]].localName)) &&
// ((n.[[Name]].uri == nulll) || (n.[[Name]].uri == a.[[Name]].uri)))
// l.append (a);
xml->getQName(&m, publicNS);
if (name.matches(&m))
{
xl->_appendNode (xml);
}
}
return xl->atom();
}
// step 5 - look through all the children for a match - [[length]] implies length of children
// n isn't an attributeName so it must be a qname??
// for k = 0 to x.[[length]]-1
// if (n.localName = "*" and this[k].class == "element" and (this[k].name.localName == n.localName)
// and (!n.uri) or (this[k].class == "element) and (n.uri == this[k].name.uri)))
// xl->_append (x[k]);
if (name.isAnyName())
xl->checkCapacity(m_node->numChildren());
for (uint32 i = 0; i < m_node->numChildren(); i++)
{
E4XNode *child = m_node->_getAt(i);
Multiname m;
Multiname *m2 = 0;
if (child->getClass() == E4XNode::kElement)
{
child->getQName(&m, publicNS);
m2 = &m;
}
// if (n.localName = "*" OR this[k].class == "element" and (this[k].name.localName == n.localName)
// and (!n.uri) or (this[k].class == "element) and (n.uri == this[k].name.uri)))
// xl->_append (x[k]);
if (name.matches(m2))
{
xl->_appendNode (child);
}
}
return xl->atom();
}
void XMLObject::setMultinameProperty(const Multiname* name_in, Atom V)
{
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
Multiname m;
toplevel->CoerceE4XMultiname(name_in, m);
// step 3
if (!m.isAnyName() && !m.isAttr())
{
Stringp name = m.getName();
uint32 index;
if (AvmCore::getIndexFromString (name, &index))
{
// Spec says: NOTE: this operation is reserved for future versions of E4X
toplevel->throwTypeError(kXMLAssignmentToIndexedXMLNotAllowed);
}
}
// step 4
if (getClass() & (E4XNode::kText | E4XNode::kCDATA | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute))
return;
Atom c;
if (AvmCore::atomToXMLList(V))
{
XMLListObject *src = AvmCore::atomToXMLList(V);
if ((src->_length() == 1) && src->_getAt(0)->getClass() & (E4XNode::kText | E4XNode::kAttribute))
{
c = core->string(V)->atom();
}
else
{
c = src->_deepCopy()->atom();
}
}
else if (AvmCore::atomToXML(V))
{
XMLObject *x = AvmCore::atomToXMLObject(V);
if (x->getClass() & (E4XNode::kText | E4XNode::kAttribute))
{
// This string is converted into a XML object below in step 2(g)(iii)
c = core->string(V)->atom();
}
else
{
c = x->_deepCopy()->atom();
}
}
else
{
#ifdef STRING_DEBUG
String *foo = core->string(V);
#endif // STRING_DEBUG
c = core->string(V)->atom();
}
// step 5
//Atom n = core->ToXMLName (P);
// step 6
//Atom defaultNamespace = core->getDefaultNamespace()->atom();
// step 7
if (m.isAttr())
{
// step 7b
Stringp sc;
if (AvmCore::isXMLList(c))
{
XMLListObject *xl = AvmCore::atomToXMLList(c);
if (!xl->_length())
{
sc = core->kEmptyString;
}
else
{
StringBuffer output (core);
output << core->string (xl->_getAt (0)->atom());
for (uint32 i = 1; i < xl->_length(); i++)
{
output << " " << core->string (xl->_getAt (i)->atom());
}
sc = core->newStringUTF8(output.c_str());
}
}
else // step 7c
{
sc = core->string (c);
}
// step 7d
int a = -1; // -1 is null in spec
// step 7e
for (uint32 j = 0; j < this->m_node->numAttributes(); j++)
{
E4XNode *x = m_node->getAttribute(j);
Multiname m2;
x->getQName(&m2, publicNS);
if (m.matches(&m2))
{
if (a == -1)
{
a = j;
}
else
{
this->deleteMultinameProperty(&m2);
// notification occurrs in deleteproperty
}
}
}
Stringp name = !m.isAnyName() ? m.getName() : NULL;
Atom nameAtom = name ? name->atom() : nullStringAtom;
if (a == -1) // step 7f
{
E4XNode *e = new (core->GetGC()) AttributeE4XNode(this->m_node, sc);
Namespace *ns = 0;
if (m.namespaceCount() == 1)
ns = m.getNamespace();
e->setQName(core, name, ns);
this->m_node->addAttribute (e);
e->_addInScopeNamespace(core, ns, publicNS);
nonChildChanges(xmlClass()->kAttrAdded, nameAtom, sc->atom());
}
else // step 7g
{
E4XNode *x = m_node->getAttribute(a);
Stringp prior = x->getValue();
x->setValue (sc);
nonChildChanges(xmlClass()->kAttrChanged, nameAtom, (prior) ? prior->atom() : undefinedAtom);
}
// step 7h
return;
}
if (!m.isAnyName())
{
// step 8
bool isValidName = core->isXMLName(m.getName()->atom());
// step 9
if (!isValidName)
return;
}
// step 10
int32 i = -1; // -1 is undefined in spec
bool primitiveAssign = ((!AvmCore::isXML(c) && !AvmCore::isXMLList(c)) && (!m.isAnyName()));
// step 12
bool notify = notifyNeeded(getNode());
for (int k = _length() - 1; k >= 0; k--)
{
E4XNode *x = m_node->_getAt(k);
Multiname mx;
Multiname *m2 = 0;
if (x->getClass() == E4XNode::kElement)
{
x->getQName(&mx, publicNS);
m2 = &mx;
}
if (m.matches(m2))
{
// remove n-1 nodes of n matching
if (i != -1)
{
E4XNode* was = m_node->_getAt(i);
m_node->_deleteByIndex (i);
// notify
if (notify && (was->getClass() == E4XNode::kElement))
{
XMLObject* nd = new (core->GetGC()) XMLObject (toplevel->xmlClass(), was);
childChanges(xmlClass()->kNodeRemoved, nd->atom());
}
}
i = k;
}
}
// step 13
if (i == -1)
{
i = _length();
if (primitiveAssign)
{
E4XNode *e = new (core->GetGC()) ElementE4XNode (m_node);
// We use m->namespaceCount here to choose to use the default xml namespace
// name here for an unqualified prop access. For a qualified access,
// there will be only one namespace
Stringp name = m.getName();
Namespace *ns;
if (m.namespaceCount() == 1)
ns = m.getNamespace();
else
ns = toplevel->getDefaultNamespace();
e->setQName (core, name, ns);
XMLObject *y = new (core->GetGC()) XMLObject (toplevel->xmlClass(), e);
m_node->_replace (core, toplevel, i, y->atom());
e->_addInScopeNamespace (core, ns, publicNS);
}
}
// step 14
if (primitiveAssign)
{
E4XNode *xi = m_node->_getAt(i);
// children are being removed notify parent if necc.
bool notify = notifyNeeded(xi);
XMLObject* target = (notify) ? new (core->GetGC()) XMLObject(xmlClass(), xi) : 0;
int count = xi->numChildren();
for(int r=0;notify && (r<count); r++)
{
E4XNode* ild = xi->_getAt(r);
if (ild->getClass() == E4XNode::kElement)
{
XMLObject* nd = new (core->GetGC()) XMLObject (toplevel->xmlClass(), ild);
target->childChanges(xmlClass()->kNodeRemoved, nd->atom());
}
}
// remember node if there was one...
Atom prior = undefinedAtom;
if (notify && count > 0)
{
XMLObject* nd = new (core->GetGC()) XMLObject (toplevel->xmlClass(), xi->_getAt(0));
prior = nd->atom();
}
// step 14a - delete all properties of x[i]
xi->clearChildren();
Stringp s = core->string (c);
if (s->length())
{
xi->_replace (core, toplevel, i, c, prior);
}
}
else
{
E4XNode* prior = m_node->_replace (core, toplevel, i, c);
if (notifyNeeded(getNode()))
{
// The above _replace call may be used to insert new nodes at the end. However, if a null is inserted
// the effect is as though nothing was inserted. Test for this case.
if (m_node->_length() > (uint32)i)
{
XMLObject* xml = new (core->GetGC()) XMLObject(xmlClass(), m_node->_getAt(i));
childChanges( (prior) ? xmlClass()->kNodeChanged : xmlClass()->kNodeAdded, xml->atom(), prior);
}
}
}
return;
}
bool XMLObject::deleteMultinameProperty(const Multiname* name_in)
{
AvmCore *core = this->core();
Multiname m;
toplevel()->CoerceE4XMultiname(name_in, m);
// step 1
if (!m.isAnyName() && !m.isAttr())
{
Stringp name = m.getName();
uint32 index;
if (AvmCore::getIndexFromString (name, &index))
{
// Spec says: NOTE: this operation is reserved for future versions of E4X
// In Rhino, this silently fails
return true;
}
}
if (m.isAttr())
{
uint32 j = 0;
while (j < m_node->numAttributes())
{
E4XNode *x = m_node->getAttribute(j);
Multiname m2;
x->getQName(&m2, publicNS);
if (m.matches(&m2))
{
x->setParent(NULL);
// remove the attribute from m_attributes
m_node->getAttributes()->removeAt (j);
Multiname previous;
x->getQName(&previous, publicNS);
Stringp name = previous.getName();
Stringp val = x->getValue();
nonChildChanges(xmlClass()->kAttrRemoved, (name) ? name->atom() : undefinedAtom, (val) ? val->atom() : undefinedAtom);
}
else
{
j++;
}
}
return true;
}
bool notify = notifyNeeded(m_node);
uint32 q = 0;
while (q < _length())
{
E4XNode *x = m_node->_getAt(q);
Multiname mx;
Multiname *m2 = 0;
bool isElem = x->getClass() == (E4XNode::kElement) ? true : false;
if (isElem)
{
x->getQName(&mx, publicNS);
m2 = &mx;
}
if (m.matches(m2))
{
x->setParent (NULL);
m_node->_deleteByIndex (q);
if (notify && isElem)
{
XMLObject *r = new (core->GetGC()) XMLObject (xmlClass(), x);
childChanges(xmlClass()->kNodeRemoved, r->atom());
}
}
else
{
q++;
// if (dp > 0)
// rename property (q) to (q-dp)
// this automatically gets taken care of by deleteByIndex
}
}
// x.length = x.length - dp
// this is handled b _deleteByIndex logic
return true;
}
Atom XMLObject::getDescendants(const Multiname* name_in) const
{
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
core->stackCheck(toplevel);
Multiname m;
toplevel->CoerceE4XMultiname(name_in, m);
XMLListObject *l = new (core->GetGC()) XMLListObject(toplevel->xmlListClass());
if (m.isAttr())
{
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
E4XNode *ax = m_node->getAttribute(i);
Multiname m2;
AvmAssert(ax->getQName(&m2, publicNS));
ax->getQName(&m2, publicNS);
if (m.matches(&m2))
{
// for each atribute, if it's name equals m,
l->_appendNode (ax);
}
}
}
for (uint32 k = 0; k < _length(); k++)
{
E4XNode *child = m_node->_getAt(k);
if (!m.isAttr())
{
Multiname mx;
Multiname *m2 = 0;
if (child->getClass() == E4XNode::kElement)
{
child->getQName(&mx, publicNS);
m2 = &mx;
}
if (m.matches(m2))
{
l->_appendNode (child);
}
}
XMLObject *co = new (core->GetGC()) XMLObject(toplevel->xmlClass(), child);
Atom dq = co->getDescendants (&m);
delete co;
XMLListObject *dql = AvmCore::atomToXMLList(dq);
if (dql && dql->_length())
{
l->_append (dq);
}
}
return l->atom();
}
// E4X 9.1.1.2, pg 13 - [[PUT]]
// E4X errata:
// 9.1.1.2 Move steps 3 and 4 to before 1 and 2, to avoid wasted effort in
// ToString or [[DeepCopy]].
void XMLObject::setAtomProperty(Atom P, Atom V)
{
Multiname m;
toplevel()->ToXMLName(P, m);
setMultinameProperty(&m, V);
}
Atom XMLObject::getUintProperty(uint32 index) const
{
if (index == 0)
return this->atom();
else
return undefinedAtom;
}
void XMLObject::setUintProperty(uint32 /*i*/, Atom /*value*/)
{
// Spec says: NOTE: this operation is reserved for future versions of E4X
toplevel()->throwTypeError(kXMLAssignmentToIndexedXMLNotAllowed);
}
bool XMLObject::delUintProperty(uint32 /*i*/)
{
// Spec says: NOTE: this operation is reserved for future versions of E4X
// In Rhino, this silently fails
return true;
}
// E4X 9.1.1.3, pg 14 - [[DELETE]]
bool XMLObject::deleteAtomProperty(Atom P)
{
Multiname m;
toplevel()->ToXMLName(P, m);
return deleteMultinameProperty(&m);
}
// E4X 9.1.1.5, ??
// [[DefaultValue]] ??
bool XMLObject::hasUintProperty(uint32 index) const
{
return (index == 0);
}
bool XMLObject::hasMultinameProperty(const Multiname* name_in) const
{
Multiname m;
toplevel()->CoerceE4XMultiname(name_in, m);
if (!m.isAnyName() && !m.isAttr())
{
Stringp name = m.getName();
uint32 index;
if (AvmCore::getIndexFromString (name, &index))
{
return (index == 0);
}
}
if (m.isAttr())
{
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
E4XNode *ax = m_node->getAttribute(i);
Multiname m2;
if (ax->getQName(&m2, publicNS) && (m.matches(&m2)))
{
return true;
}
}
return false;
}
// n is a QName
for (uint32 k = 0; k < m_node->_length(); k++)
{
E4XNode *child = m_node->_getAt(k);
Multiname mx;
Multiname *m2 = 0;
if (child->getClass() == E4XNode::kElement)
{
child->getQName(&mx, publicNS);
m2 = &mx;
}
if (m.matches(m2))
{
return true;
}
}
return false;
}
// E4X 9.1.1.6, 16
bool XMLObject::hasAtomProperty(Atom P) const
{
Multiname m;
toplevel()->ToXMLName (P, m);
return hasMultinameProperty(&m);
}
// E4X 9.1.1.7, page 16
XMLObject *XMLObject::_deepCopy () const
{
AvmCore *core = this->core();
E4XNode *e = m_node->_deepCopy (core, toplevel(), publicNS);
XMLObject *y = new (core->GetGC()) XMLObject(xmlClass(), e);
return y;
}
// E4X 9.1.1.8, page 17
XMLListObject *XMLObject::AS3_descendants(Atom P) const
{
Multiname m;
toplevel()->ToXMLName (P, m);
return AvmCore::atomToXMLList (getDescendants (&m));
}
// E4X 9.1.1.10, page 18
Atom XMLObject::_resolveValue ()
{
return this->atom();
}
Namespace *XMLObject::GenerateUniquePrefix (Namespace *ns, const AtomArray *namespaces) const
{
AvmCore *core = this->core();
// should only be called when a namespace doesn't have a prefix
AvmAssert (ns->getPrefix() == undefinedAtom);
// Try to use the empty string as a first try (ISNS changes)
uint32 i;
for (i = 0; i < namespaces->getLength(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (namespaces->getAt(i));
if (ns->getPrefix() == core->kEmptyString->atom())
break;
}
if (i == namespaces->getLength())
{
return core->newNamespace (core->kEmptyString->atom(), ns->getURI()->atom());
}
// Rhino seems to start searching with whatever follows "://www" or "://"
//String *origURI = core()->string(ns->getURI());
wchar s[4];
s[0] = s[1] = s[2] = 'a';
s[3] = 0;
for (wchar x1 = 'a'; x1 <= 'z'; x1++)
{
s[0] = x1;
for (wchar x2 = 'a'; x2 <= 'z'; x2++)
{
s[1] = x2;
for (wchar x3 = 'a'; x3 <= 'z'; x3++)
{
s[2] = x3;
bool bMatch = false;
Atom pre = core->internStringUTF16(s, 3)->atom();
for (uint32 i = 0; i < namespaces->getLength(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (namespaces->getAt(i));
if (pre == ns->getPrefix())
{
bMatch = true;
break;
}
}
if (!bMatch)
{
return core->newNamespace (pre, ns->getURI()->atom());
}
}
}
}
return 0;
}
// E4X 10.2, pg 29
void XMLObject::__toXMLString(StringBuffer &s, AtomArray *AncestorNamespaces, int indentLevel, bool includeChildren) const
{
AvmCore *core = this->core();
core->stackCheck(toplevel());
if (toplevel()->xmlClass()->okToPrettyPrint())
{
for (int i = 0; i < indentLevel; i++)
{
s << " ";
}
}
if (this->getClass() == E4XNode::kText) // CDATA checked below
{
if (toplevel()->xmlClass()->okToPrettyPrint())
{
// v = removing leading and trailing whitespace from x.value
// return escapeElementValue (v);
s << core->EscapeElementValue(m_node->getValue(), true);
return;
}
else
{
s << core->EscapeElementValue(m_node->getValue(), false);
return;
}
}
if (this->getClass() == E4XNode::kCDATA)
{
s << "<![CDATA[" << m_node->getValue() << "]]>";
return;
}
if (this->getClass() == E4XNode::kAttribute)
{
s << core->EscapeAttributeValue (m_node->getValue()->atom());
return;
}
if (this->getClass() == E4XNode::kComment)
{
s << "<!--";
s << m_node->getValue();
s << "-->";
return;
}
if (this->getClass() == E4XNode::kProcessingInstruction) // step 7
{
s << "<?";
Multiname m;
AvmAssert (m_node->getQName(&m, publicNS) != 0);
if (m_node->getQName(&m, publicNS))
{
s << m.getName() << " ";
}
s << m_node->getValue() << "?>";
return;
}
// We're a little different than the spec here. Instead of each XMLObject
// keeping track of its entire in-scope namespace list (all the way to the
// topmost parent), the XMLObject only knows about its own declared nodes.
// So when were converting to a string, we need to build the inScopeNamespace
// list here.
AtomArray *inScopeNS = new (core->GetGC()) AtomArray();
m_node->BuildInScopeNamespaceList (core, inScopeNS);
uint32 origLength = AncestorNamespaces->getLength();
// step 8 - ancestorNamespaces passed in
// step 9/10 - add in our namespaces into ancestorNamespaces if there are no conflicts
for (uint32 i = 0; i < inScopeNS->getLength(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (inScopeNS->getAt(i));
uint32 j;
for (j = 0; j < AncestorNamespaces->getLength(); j++)
{
Namespace *ns2 = AvmCore::atomToNamespace (AncestorNamespaces->getAt(j));
#ifdef STRING_DEBUG
Stringp u1 = ns->getURI();
Stringp p1 = core->string(ns->getPrefix());
Stringp u2 = ns2->getURI();
Stringp p2 = core->string(ns2->getPrefix());
#endif
if ((ns->getURI() == ns2->getURI()) && (ns->getPrefix() == ns2->getPrefix()))
break;
}
if (j == AncestorNamespaces->getLength()) // a match was not found
{
AncestorNamespaces->push (ns->atom());
}
}
// step 11 - new ISNS changes
// If this node's namespace has an undefined prefix, generate a new one
Multiname m;
AvmAssert (getNode()->getQName(&m, publicNS));
getNode()->getQName(&m, publicNS);
Namespace *thisNodesNamespace = GetNamespace (m, AncestorNamespaces);
AvmAssert(thisNodesNamespace != 0);
if (thisNodesNamespace->getPrefix() == undefinedAtom)
{
// find a prefix and add this namespace to our list
thisNodesNamespace = GenerateUniquePrefix (thisNodesNamespace, AncestorNamespaces);
AncestorNamespaces->push (thisNodesNamespace->atom());
}
String *nsPrefix = core->string (thisNodesNamespace->getPrefix());
// If any of this node's attribute's namespaces have an undefined prefix, generate a new one
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
E4XNode *an = m_node->getAttribute(i);
AvmAssert(an != 0);
AvmAssert(an->getClass() == E4XNode::kAttribute);
Multiname nam;
if (an->getQName(&nam, publicNS))
{
Namespace* ns = GetNamespace(nam, AncestorNamespaces);
AvmAssert(ns != 0);
if (ns->getPrefix() == undefinedAtom)
{
// find a prefix and add this namespace to our list
ns = GenerateUniquePrefix (ns, AncestorNamespaces);
AncestorNamespaces->push (ns->atom());
}
}
}
// step 12
s << "<";
// step13 - insert namespace prefix if we have one
if (nsPrefix != core->kEmptyString)
{
s << nsPrefix << ":";
}
// step 14
AvmAssert (!m.isAnyName());
s << m.getName();
// step 15 - attrAndNamespaces = sum of x.attributes and namespaceDeclarations
// step 16
// for each an in attrAndNamespaces
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
// step 17a
E4XNode *an = m_node->getAttribute(i);
AvmAssert(an != 0);
AvmAssert(an->getClass() == E4XNode::kAttribute);
Multiname nam;
if (an->getQName(&nam, publicNS))
{
s << " ";
// step16b-i - ans = an->getName->getNamespace(AncestorNamespace);
AvmAssert(nam.isAttr());
Namespace *attr_ns = GetNamespace (nam, AncestorNamespaces);
//!!@step16b-ii - should never get hit now with revised 10.2.1 step 11.
AvmAssert(attr_ns->getPrefix() != undefinedAtom);
// step16b-iii
if (attr_ns && attr_ns->hasPrefix ())
{
s << core->string(attr_ns->getPrefix()) << ":";
}
//step16b-iv
s << nam.getName();
//step16c - namespace case - see below
//step 16d
s << "=\"";
//step 16e
s << core->EscapeAttributeValue(an->getValue()->atom());
//step 16f - namespace case
//step 16g
s << "\"";
}
}
// This adds any NS that were added to our ancestor namespace list (from origLength on up)
for (uint32 i = origLength; i < AncestorNamespaces->getLength(); i++)
{
Namespace *an = AvmCore::atomToNamespace(AncestorNamespaces->getAt(i));
if (an->getURI() != core->kEmptyString)
{
s << " xmlns";
AvmAssert (an->getPrefix() != undefinedAtom);
if (an->getPrefix() != core->kEmptyString->atom())
{
// 17c iii
s << ":" << core->string(an->getPrefix());
}
// 17d
s << "=\"";
//step 17f - namespace case
s << an->getURI();
//step 17g
s << "\"";
}
}
// if (thisNodesNamespace)
// AncestorNamespaces->push (thisNodesNamespace->atom());
// step 18
if (!m_node->numChildren())
{
s << "/>";
return;
}
// step 19
s << ">";
// Added by mmorearty for the debugger
if (!includeChildren)
{
return;
}
// step 20
E4XNode *firstChild = m_node->_getAt(0);
AvmAssert(firstChild != 0);
bool bIndentChildren = ((_length() > 1) || (firstChild->getClass() & ~(E4XNode::kText | E4XNode::kCDATA)));
// step 21/22
int nextIndentLevel = 0;
if (toplevel()->xmlClass()->get_prettyPrinting() && bIndentChildren)
{
nextIndentLevel = indentLevel + toplevel()->xmlClass()->get_prettyIndent();
}
// We need to prune any namespaces with duplicate prefixes in our AncestorNamespace
// array to prevent shadowing of similar namespaces. Bug 153363.
// var x = <order xmlns:x="x">
// <item id="1" xmlns:x="x2">
// <menuName xmlns:x="x" x:foo='10'>burger</menuName>
// <price>3.95</price>
// </item>
// </order>;
//
// The namespace for menuName should be output even though the identical namespace
// was output for the top node. (Since the item node is using an incompatible
// namespace with the same prefix.)
AtomArray *newNamespaceArray = new (core->GetGC()) AtomArray();
uint32 anLen = AncestorNamespaces->getLength();
for (uint32 i = 0; i < anLen; i++)
{
Namespace *first = AvmCore::atomToNamespace(AncestorNamespaces->getAt(i));
if (i < origLength)
{
uint32 j;
for (j = origLength; j < anLen; j++)
{
Namespace *second = AvmCore::atomToNamespace(AncestorNamespaces->getAt(j));
if (second->getPrefix() == first->getPrefix())
{
break;
}
}
// No match, push our namespace on the list.
if (j == anLen)
{
newNamespaceArray->push (first->atom());
}
}
else
{
newNamespaceArray->push (first->atom());
}
}
uint32 namespaceLength = newNamespaceArray->getLength();
// step 23
for (uint32 i = 0; i < _length(); i++)
{
// step 23b
E4XNode *child = m_node->_getAt(i);
XMLObject *xo = new (core->GetGC()) XMLObject(toplevel()->xmlClass(), child);
if (toplevel()->xmlClass()->okToPrettyPrint() && bIndentChildren)
{
s << "\n";
}
xo->__toXMLString (s, newNamespaceArray, nextIndentLevel, includeChildren);
// Our __toXMLString call might have added new namespace onto our list. We don't want to
// save these new namespaces so clear them out here.
newNamespaceArray->setLength (namespaceLength);
}
// Part of the latest spec
if (toplevel()->xmlClass()->okToPrettyPrint() && bIndentChildren)
{
s << "\n";
}
//step 24
if (toplevel()->xmlClass()->okToPrettyPrint() && bIndentChildren)
{
for (int i = 0; i < indentLevel; i++)
{
s << " ";
}
}
//step 25
s << "</";
//step 26
if (nsPrefix != core->kEmptyString)
{
s << nsPrefix << ":";
}
//step 27
s << m.getName() << ">";
//step 28
return;
}
// E4X 12.2, page 59
// Support for for-in, for-each for XMLObjects
Atom XMLObject::nextName(int index)
{
AvmAssert(index > 0);
if (index == 1)
{
AvmCore *core = this->core();
return core->internInt (0)->atom();
}
else
{
return nullStringAtom;
}
}
Atom XMLObject::nextValue(int index)
{
AvmAssert(index > 0);
if (index == 1)
return this->atom();
else
return undefinedAtom;
}
int XMLObject::nextNameIndex(int index)
{
AvmAssert(index >= 0);
// XML types just return one value
if (index == 0)
return 1;
else
return 0;
}
XMLObject *XMLObject::AS3_addNamespace (Atom _namespace)
{
AvmCore *core = this->core();
if (core->isNamespace (_namespace))
{
m_node->_addInScopeNamespace (core, AvmCore::atomToNamespace(_namespace), publicNS);
}
else
{
Namespace *ns = core->newNamespace (_namespace);
m_node->_addInScopeNamespace (core, ns, publicNS);
_namespace = ns->atom();
}
nonChildChanges(xmlClass()->kNamespaceAdded, _namespace);
return this;
}
XMLObject *XMLObject::AS3_appendChild (Atom child)
{
AvmCore *core = this->core();
if(!(PoolObject::kbug444630 & traits()->pool->bugFlags))
{
if (AvmCore::isXML(child))
{
child = AvmCore::atomToXMLObject(child)->atom();
}
else if (AvmCore::isXMLList(child))
{
child = AvmCore::atomToXMLList(child)->atom();
}
else // all other types go through XML constructor as a string
{
child = xmlClass()->ToXML (core->string(child)->atom());
}
}
Atom children = getStringProperty(core->kAsterisk);
XMLListObject *cxl = AvmCore::atomToXMLList(children);
int index = _length();
cxl->setUintProperty (index, child);
return this;
}
XMLListObject *XMLObject::AS3_attribute (Atom arg)
{
// E4X 13.4.4.4
// name= ToAttributeName (attributeName);
// return [[get]](name)
return AvmCore::atomToXMLList(getAtomProperty(toplevel()->ToAttributeName(arg)->atom()));
}
XMLListObject *XMLObject::AS3_attributes ()
{
// E4X 13.4.4.5
// name= ToAttributeName ("*");
// return [[get]](name)
return AvmCore::atomToXMLList(getAtomProperty(toplevel()->ToAttributeName(core()->kAsterisk)->atom()));
}
XMLListObject *XMLObject::AS3_child (Atom P)
{
AvmCore *core = this->core();
// We have an integer argument - direct child lookup
uint32 index;
if (AvmCore::getIndexFromString (core->string(P), &index))
{
XMLListObject *xl = new (core->GetGC()) XMLListObject(toplevel()->xmlListClass());
if (index < m_node->numChildren())
{
xl->_appendNode (m_node->_getAt(index));
}
return xl;
}
return AvmCore::atomToXMLList(getAtomProperty(P));
}
int XMLObject::AS3_childIndex()
{
return m_node->childIndex();
}
XMLListObject *XMLObject::AS3_children ()
{
return AvmCore::atomToXMLList(getStringProperty(core()->kAsterisk));
}
// E4X 13.4.4.8, pg 75
XMLListObject *XMLObject::AS3_comments ()
{
AvmCore *core = this->core();
XMLListObject *l = new (core->GetGC()) XMLListObject(toplevel()->xmlListClass(), this->atom());
for (uint32 i = 0; i < m_node->_length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child->getClass() == E4XNode::kComment)
{
l->_appendNode (child);
}
}
return l;
}
// E4X 13.4.4.10, pg 75
bool XMLObject::AS3_contains (Atom value)
{
AvmCore *core = this->core();
// !!@ Rhino returns false for this case...
// var xml = new XML("simple");
// print ("contains: " + xml.contains ("simple"));
// ...which seems to imply that this routine is calling _equals and not
// does a "comparison x == value" as stated in the spec. We'll mimic
// Rhino for the time being but the correct behavior needs to be determined
if (this->atom() == value)
return true;
if (!AvmCore::isXML(value))
return false;
E4XNode *v = AvmCore::atomToXML(value);
return getNode()->_equals(toplevel(), core, v); // rhino
//SPEC - return (core()->equals (this->atom(), value) == trueAtom);
}
// E4X 13.4.4.11, pg 76
XMLObject *XMLObject::AS3_copy ()
{
return _deepCopy ();
}
// E4X 13.4.4.13, pg 76
XMLListObject *XMLObject::AS3_elements (Atom name) // name defaults to '*'
{
AvmCore *core = this->core();
Multiname m;
toplevel()->ToXMLName(name, m);
XMLListObject *l = new (core->GetGC()) XMLListObject(toplevel()->xmlListClass(), this->atom());
for (uint32 i = 0; i < _length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child->getClass() == E4XNode::kElement)
{
Multiname m2;
child->getQName(&m2, publicNS);
// if name.localName = "*" or name.localName =child->name.localName)
// and (name.uri == null) or (name.uri == child.name.uri))
if (m.matches(&m2))
{
// if name.localName = "*" or name.localName =child->name.localName)
// and (name.uri == null) or (name.uri == child.name.uri))
l->_appendNode (child);
}
}
}
return l;
}
// E4X 13.4.4.14, page 77
bool XMLObject::XML_AS3_hasOwnProperty (Atom P)
{
if (hasAtomProperty(P))
return true;
// if this has a property with name ToSString(P), return true;
// !!@ spec talks about prototype object being different from regular XML object
return false;
}
// E4X 13.4.4.15, page 77
bool XMLObject::AS3_hasComplexContent ()
{
return m_node->hasComplexContent();
}
// E4X 13.4.4.16, page 77
bool XMLObject::AS3_hasSimpleContent ()
{
return m_node->hasSimpleContent();
}
// E4X 13.4.4.17, page 78
ArrayObject *XMLObject::AS3_inScopeNamespaces ()
{
AvmCore *core = this->core();
// step 2
AtomArray *inScopeNS = new (core->GetGC()) AtomArray();
// step 3
m_node->BuildInScopeNamespaceList (core, inScopeNS);
ArrayObject *a = toplevel()->arrayClass->newArray(inScopeNS->getLength());
uint32 i;
for (i = 0; i < inScopeNS->getLength(); i++)
{
a->setUintProperty (i, inScopeNS->getAt(i));
}
// !!@ Rhino behavior always seems to return at least one NS
if (!inScopeNS->getLength())
{
// NOTE use caller's public
a->setUintProperty (i, core->findPublicNamespace()->atom());
}
return a;
}
// E4X 13.4.4.18, page 78
Atom XMLObject::AS3_insertChildAfter (Atom child1, Atom child2)
{
AvmCore *core = this->core();
Toplevel *toplevel = this->toplevel();
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute | E4XNode::kCDATA))
return undefinedAtom;
if(!(PoolObject::kbug444630 & traits()->pool->bugFlags))
{
if (AvmCore::isXML(child2))
{
child2 = AvmCore::atomToXMLObject(child2)->atom();
}
else if (AvmCore::isXMLList(child2))
{
child2 = AvmCore::atomToXMLList(child2)->atom();
}
else // all other types go through XML constructor as a string
{
child2 = xmlClass()->ToXML (core->string(child2)->atom());
}
}
if (AvmCore::isNull(child1))
{
m_node->_insert (core, toplevel, 0, child2);
childChanges(xmlClass()->kNodeAdded, child2);
return this->atom();
}
else
{
E4XNode *c1 = AvmCore::atomToXML(child1);
// Errata extension to E4X spec - treat XMLList with length=1 as a XMLNode
if (!c1 && AvmCore::isXMLList(child1))
{
XMLListObject *xl = AvmCore::atomToXMLList(child1);
if (xl->_length() == 1)
c1 = xl->_getAt(0)->m_node;
}
if (c1)
{
for (uint32 i = 0; i < _length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child == c1)
{
m_node->_insert (core, toplevel, i + 1, child2);
childChanges(xmlClass()->kNodeAdded, child2);
return this->atom();
}
}
}
}
return undefinedAtom;
}
// E4X 13.4.4.19, page 79
Atom XMLObject::AS3_insertChildBefore (Atom child1, Atom child2)
{
AvmCore *core = this->core();
Toplevel *toplevel = this->toplevel();
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute | E4XNode::kCDATA))
return undefinedAtom;
if(!(PoolObject::kbug444630 & traits()->pool->bugFlags))
{
if (AvmCore::isXML(child2))
{
child2 = AvmCore::atomToXMLObject(child2)->atom();
}
else if (AvmCore::isXMLList(child2))
{
child2 = AvmCore::atomToXMLList(child2)->atom();
}
else // all other types go through XML constructor as a string
{
child2 = xmlClass()->ToXML (core->string(child2)->atom());
}
}
if (AvmCore::isNull(child1))
{
m_node->_insert (core, toplevel, _length(), child2);
childChanges(xmlClass()->kNodeAdded, child2);
return this->atom();
}
else
{
E4XNode *c1 = AvmCore::atomToXML(child1);
// Errata extension to E4X spec - treat XMLList with length=1 as a XMLNode
if (!c1 && AvmCore::isXMLList(child1))
{
XMLListObject *xl = AvmCore::atomToXMLList(child1);
if (xl->_length() == 1)
c1 = xl->_getAt(0)->m_node;
}
if (c1)
{
for (uint32 i = 0; i < _length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child == c1)
{
m_node->_insert (core, toplevel, i, child2);
childChanges(xmlClass()->kNodeAdded, child2);
return this->atom();
}
}
}
}
return undefinedAtom;
}
// E4X 13.4.4.21, page 80
Atom XMLObject::AS3_localName ()
{
Multiname m;
if (m_node->getQName(&m, publicNS) == 0)
{
return nullStringAtom;
}
else
{
return m.getName()->atom();
}
}
// E4X 13.4.4.22, page 80
Atom XMLObject::AS3_name ()
{
AvmCore *core = this->core();
Multiname m;
if (!m_node->getQName(&m, publicNS))
return nullObjectAtom;
return (new (core->GetGC(), toplevel()->qnameClass()->ivtable()->getExtraSize()) QNameObject(toplevel()->qnameClass(), m))->atom();
}
// E4X 13.4.4.23, page 80
Atom XMLObject::_namespace (Atom p_prefix, int argc) // prefix is optional
{
AvmAssert(argc == 0 || argc == 1);
AvmCore *core = this->core();
// step 2
AtomArray *inScopeNS = new (core->GetGC()) AtomArray();
// step 3
m_node->BuildInScopeNamespaceList (core, inScopeNS);
// step 5
if (!argc)
{
// step 5a
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kCDATA | E4XNode::kProcessingInstruction))
return nullObjectAtom;
// step 5b
// Return the result of calling [[GetNamespace]] method of
// x.[[Name]] with argument inScopeNS
Multiname m;
AvmAssert(getQName(&m));
getQName(&m);
Namespace *ns = GetNamespace (m, inScopeNS);
return (ns->atom());
}
else
{
Atom prefix = core->internString(core->string (p_prefix))->atom();
for (uint32 i = 0; i < inScopeNS->getLength(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (inScopeNS->getAt(i));
if (ns->getPrefix() == prefix)
return ns->atom();
}
return undefinedAtom;
}
}
// 13.4.4.24, pg 80-81
ArrayObject *XMLObject::AS3_namespaceDeclarations ()
{
AvmCore *core = this->core();
ArrayObject *a = toplevel()->arrayClass->newArray();
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute | E4XNode::kCDATA))
return a;
E4XNode *y = m_node->getParent();
// step 4+5
AtomArray *ancestorNS = new (core->GetGC()) AtomArray();
if (y)
y->BuildInScopeNamespaceList (core, ancestorNS);
uint32 arrayIndex = 0;
// step 7+8+9+10
for (uint32 i = 0; i < m_node->numNamespaces(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (m_node->getNamespaces()->getAt(i));
if (!ns->hasPrefix ())
{
// Emulating Rhino behavior
if (ns->getURI() != core->kEmptyString)
{
bool bMatch = false;
for (uint32 j = 0; j < ancestorNS->getLength(); j++)
{
Namespace *ns2 = AvmCore::atomToNamespace (ancestorNS->getAt(j));
if (ns->getURI() == ns2->getURI())
{
bMatch = true;
break;
}
}
if (!bMatch)
{
a->setUintProperty (arrayIndex++, ns->atom());
}
}
}
else // ns.prefix is NOT empty
{
bool bMatch = false;
for (uint32 j = 0; j < ancestorNS->getLength(); j++)
{
Namespace *ns2 = AvmCore::atomToNamespace (ancestorNS->getAt(j));
if (ns->getPrefix() == ns2->getPrefix() && ns->getURI() == ns2->getURI())
{
bMatch = true;
break;
}
}
if (!bMatch)
{
a->setUintProperty (arrayIndex++, ns->atom());
}
}
}
return a;
}
String *XMLObject::AS3_nodeKind () const
{
return m_node->nodeKind(toplevel());
}
XMLObject *XMLObject::AS3_normalize ()
{
AvmCore* core = this->core();
bool notify = notifyNeeded(getNode());
uint32 i = 0;
while (i < _length())
{
E4XNode *x = m_node->_getAt(i);
if (x->getClass() == E4XNode::kElement)
{
XMLObject *xo = new (core->GetGC()) XMLObject(toplevel()->xmlClass(), x);
xo->normalize();
delete xo;
i++;
}
else if (x->getClass() & (E4XNode::kText | E4XNode::kCDATA))
{
Stringp prior = x->getValue();
while (((i + 1) < _length()) && (m_node->_getAt(i + 1)->getClass() & (E4XNode::kText | E4XNode::kCDATA)))
{
E4XNode *x2 = m_node->_getAt(i + 1);
x->setValue (core->concatStrings(x->getValue(), x2->getValue()));
m_node->_deleteByIndex (i + 1);
if (notify)
{
XMLObject *nd = new (core->GetGC()) XMLObject (xmlClass(), x2);
childChanges(xmlClass()->kNodeRemoved, nd->atom());
}
}
/// Need to check if string is "empty" - 0 length or filled with whitespace
if (x->getValue()->isWhitespace())
{
E4XNode* prior = m_node->_getAt(i);
m_node->_deleteByIndex (i);
if (notify)
{
XMLObject *nd = new (core->GetGC()) XMLObject (xmlClass(), prior);
childChanges(xmlClass()->kNodeRemoved, nd->atom());
}
}
else
{
i++;
}
// notify if the node has changed value
Stringp current = x->getValue();
if ((current != prior) && notify)
{
XMLObject *xo = new (core->GetGC()) XMLObject (xmlClass(), x);
xo->nonChildChanges(xmlClass()->kTextSet, current->atom(), (prior) ? prior->atom() : undefinedAtom);
}
}
else
{
i++;
}
}
return this;
}
Atom XMLObject::AS3_parent ()
{
if (m_node->getParent())
return (new (core()->GetGC()) XMLObject (toplevel()->xmlClass(), m_node->getParent()))->atom();
else
return undefinedAtom;
}
XMLListObject *XMLObject::AS3_processingInstructions (Atom name) // name defaults to '*'
{
AvmCore *core = this->core();
Multiname m;
toplevel()->ToXMLName(name, m);
XMLListObject *xl = new (core->GetGC()) XMLListObject(toplevel()->xmlListClass(), this->atom());
if (m.isAttr())
return xl;
for (uint32 i = 0; i < m_node->_length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child->getClass() == E4XNode::kProcessingInstruction)
{
Multiname m2;
bool bFound = child->getQName(&m2, publicNS);
// if name.localName = "*" or name.localName =child->name.localName)
// and (name.uri == null) or (name.uri == child.name.uri))
if (m.matches(bFound ? &m2 : 0))
{
xl->_appendNode (child);
}
}
}
return xl;
}
XMLObject *XMLObject::AS3_prependChild (Atom value)
{
AvmCore *core = this->core();
Toplevel *toplevel = this->toplevel();
if(!(PoolObject::kbug444630 & traits()->pool->bugFlags))
{
if (AvmCore::isXML(value))
{
value = AvmCore::atomToXMLObject(value)->atom();
}
else if (AvmCore::isXMLList(value))
{
value = AvmCore::atomToXMLList(value)->atom();
}
else // all other types go through XML constructor as a string
{
value = xmlClass()->ToXML (core->string(value)->atom());
}
}
m_node->_insert (core, toplevel, 0, value);
childChanges(xmlClass()->kNodeAdded, value);
return this;
}
bool XMLObject::XML_AS3_propertyIsEnumerable(Atom P) // NOT virtual, not an override
{
AvmCore *core = this->core();
if (core->intern(P) == core->internConstantStringLatin1("0"))
return true;
return false;
}
// 13.4.4.31, pg 83
XMLObject *XMLObject::AS3_removeNamespace (Atom nsAtom)
{
AvmCore *core = this->core();
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute | E4XNode::kCDATA))
return this;
Namespace *ns = core->isNamespace (nsAtom) ? AvmCore::atomToNamespace (nsAtom) : core->newNamespace (nsAtom);
Multiname m;
AvmAssert(getQName(&m));
getQName(&m);
Namespace *thisNS = GetNamespace (m, m_node->getNamespaces());
// step 4
if (thisNS == ns)
return this;
//step 5
for (uint32 j = 0; j < m_node->numAttributes(); j++)
{
E4XNode *a = m_node->getAttribute(j);
Multiname m;
AvmAssert(a->getQName(&m, publicNS));
a->getQName(&m, publicNS);
Namespace *anNS = GetNamespace (m, m_node->getNamespaces());
if (anNS == ns)
return this;
}
// step 6+7
int32 i = m_node->FindMatchingNamespace (core, ns);
if (i != -1)
{
m_node->getNamespaces()->removeAt(i);
}
// step 8
for (uint32 k = 0; k < _length(); k++)
{
E4XNode *p = m_node->_getAt(k);
if (p->getClass() == E4XNode::kElement)
{
XMLObject *xo = new (core->GetGC()) XMLObject(toplevel()->xmlClass(), p);
xo->removeNamespace (ns->atom());
delete xo;
}
}
// step 9
// Note about namespaces in ancestors and parents, etc.
nonChildChanges(xmlClass()->kNamespaceRemoved, ns->atom());
return this;
}
XMLObject *XMLObject::AS3_replace (Atom P, Atom value)
{
AvmCore *core = this->core();
Toplevel *toplevel = this->toplevel();
if (getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kAttribute | E4XNode::kCDATA))
return this;
Atom c;
if (AvmCore::isXML(value))
{
XMLObject *x = AvmCore::atomToXMLObject(value);
c = x->_deepCopy()->atom();
}
else if (AvmCore::isXMLList(value))
{
XMLListObject *xl = AvmCore::atomToXMLList(value);
c = xl->_deepCopy()->atom();
}
else
{
if(!(PoolObject::kbug444630 & traits()->pool->bugFlags))
c = xmlClass()->ToXML (core->string(value)->atom());
else
c = core->string(value)->atom();
}
uint32 index;
if (AvmCore::getIndexFromString (core->string(P), &index))
{
E4XNode* prior = m_node->_replace (core, toplevel, index, c);
childChanges(xmlClass()->kNodeChanged, c, prior);
return this;
}
QNameObject *qn1 = new (core->GetGC(), toplevel->qnameClass()->ivtable()->getExtraSize()) QNameObject(toplevel->qnameClass(), P);
Multiname m;
qn1->getMultiname(m);
bool notify = notifyNeeded(getNode());
int i = -1;
for (int k = int(_length()) - 1; k >= 0; k--)
{
E4XNode *x = m_node->_getAt (k);
Multiname *m2 = 0;
// m3 needs to exist outside this if scope since m2 will point to it
Multiname m3;
if (x->getClass() == E4XNode::kElement)
{
if (x->getQName(&m3, publicNS))
m2 = &m3;
}
if (m.matches(m2))
{
if (i != -1)
{
E4XNode* was = m_node->_getAt(i);
m_node->_deleteByIndex (i);
// notify
if (notify && was->getClass() == E4XNode::kElement)
{
XMLObject* nd = new (core->GetGC()) XMLObject (xmlClass(), was);
childChanges(xmlClass()->kNodeRemoved, nd->atom());
}
}
i = k;
}
}
delete qn1;
if (i == -1)
return this;
E4XNode* prior = m_node->_replace (core, toplevel, i, c);
childChanges( (prior) ? xmlClass()->kNodeChanged : xmlClass()->kNodeAdded, c, prior);
return this;
}
XMLObject *XMLObject::AS3_setChildren (Atom value)
{
setStringProperty(core()->kAsterisk, value);
return this;
}
void XMLObject::AS3_setLocalName (Atom name)
{
if (m_node->getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kCDATA))
return;
AvmCore *core = this->core();
QNameObject *qn = AvmCore::atomToQName(name);
Stringp newname;
if (qn)
{
newname = qn->get_localName();
}
else
{
newname = core->intern(name);
}
if (!core->isXMLName(newname->atom()))
toplevel()->throwTypeError(kXMLInvalidName, newname);
Multiname m;
if (this->getNode()->getQName(&m, publicNS))
{
Multiname previous;
getNode()->getQName(&previous, publicNS);
Stringp prior = previous.getName();
m.setName (newname);
getNode()->setQName (core, &m);
nonChildChanges(xmlClass()->kNameSet, m.getName()->atom(), (prior) ? prior->atom() : undefinedAtom );
}
return;
}
void XMLObject::AS3_setName (Atom name)
{
AvmCore *core = this->core();
if (m_node->getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kCDATA))
return;
if (AvmCore::isQName(name))
{
QNameObject *q = AvmCore::atomToQName(name);
if (AvmCore::isNull(q->getURI()))
{
name = q->get_localName()->atom();
}
}
QNameObject *n = new (core->GetGC(), toplevel()->qnameClass()->ivtable()->getExtraSize()) QNameObject(toplevel()->qnameClass(), name);
Stringp s = n->get_localName();
if (!core->isXMLName(s->atom()))
toplevel()->throwTypeError(kXMLInvalidName, s);
Multiname m;
if (m_node->getQName(&m, publicNS))
{
if (m_node->getClass() == E4XNode::kProcessingInstruction)
{
m_node->setQName (core, n->get_localName(), core->findPublicNamespace());
}
else // only for attribute and element nodes
{
Multiname m2;
n->getMultiname (m2);
m_node->setQName (core, &m2);
// ISNS changes
if (n->getURI() != core->kEmptyString->atom())
{
m_node->getQName(&m, publicNS); // get our new multiname
if (this->getClass() == E4XNode::kAttribute && getNode()->getParent())
{
getNode()->getParent()->_addInScopeNamespace (core, m.getNamespace(), publicNS);
}
else if (this->getClass() == E4XNode::kElement)
{
getNode()->_addInScopeNamespace (core, m.getNamespace(), publicNS);
}
}
}
nonChildChanges(xmlClass()->kNameSet, name, m.getName()->atom());
}
return;
}
void XMLObject::AS3_setNamespace (Atom ns)
{
AvmCore *core = this->core();
if (m_node->getClass() & (E4XNode::kText | E4XNode::kComment | E4XNode::kProcessingInstruction | E4XNode::kCDATA))
return;
Namespace* newns = core->newNamespace (ns);
Multiname m;
if (m_node->getQName(&m, publicNS))
{
m_node->setQName (core, m.getName(), newns);
}
// ISNS changes
if (this->getClass() == E4XNode::kAttribute && getNode()->getParent())
{
getNode()->getParent()->_addInScopeNamespace (core, newns, publicNS);
}
else if (this->getClass() == E4XNode::kElement)
{
getNode()->_addInScopeNamespace (core, newns, publicNS);
}
nonChildChanges(xmlClass()->kNamespaceSet, newns->atom());
return;
}
XMLListObject *XMLObject::AS3_text ()
{
XMLListObject *l = new (gc()) XMLListObject(toplevel()->xmlListClass(), this->atom());
for (uint32 i = 0; i < m_node->_length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if (child->getClass() & (E4XNode::kText | E4XNode::kCDATA))
{
l->_appendNode (child);
}
}
return l;
}
// E4X 10.1, page 28
Atom XMLObject::toString ()
{
AvmCore *core = this->core();
if (getClass() & (E4XNode::kText | E4XNode::kCDATA | E4XNode::kAttribute))
{
return m_node->getValue()->atom();
}
if (hasSimpleContent())
{
Stringp s = core->kEmptyString;
for (uint32 i = 0; i < _length(); i++)
{
E4XNode *child = m_node->_getAt(i);
if ((child->getClass() != E4XNode::kComment) && (child->getClass() != E4XNode::kProcessingInstruction))
{
XMLObject *xo = new (core->GetGC()) XMLObject(toplevel()->xmlClass(), child);
s = core->concatStrings(s, core->string(xo->toString()));
delete xo;
}
}
return s->atom();
}
else
{
AtomArray *AncestorNamespaces = new (core->GetGC()) AtomArray();
StringBuffer s(core);
__toXMLString(s, AncestorNamespaces, 0);
return core->newStringUTF8(s.c_str())->atom();
}
}
Stringp XMLObject::AS3_toString()
{
return core()->atomToString(toString());
}
String *XMLObject::AS3_toXMLString ()
{
AtomArray *AncestorNamespaces = new (MMgc::GC::GetGC(this)) AtomArray();
StringBuffer s(core());
__toXMLString(s, AncestorNamespaces, 0);
return core()->newStringUTF8(s.c_str());
}
#ifdef AVMPLUS_VERBOSE
Stringp XMLObject::format(AvmCore* core) const
{
//
// [mmorearty 10/24/05] Flex Builder 2.0 relies on this format in order to
// have a nice display of XML in the Variables view:
//
// "XML@hexaddr nodeKind text_to_display"
//
AtomArray *AncestorNamespaces = new (core->GetGC()) AtomArray();
StringBuffer openTag(core);
__toXMLString(openTag, AncestorNamespaces, 0, false);
Stringp openingTag = core->newStringUTF8(openTag.c_str());
Stringp result = ScriptObject::format(core);
result = result->appendLatin1(" ");
result = core->concatStrings(result, nodeKind());
result = result->appendLatin1(" ");
result = core->concatStrings(result, openingTag);
return result;
}
#endif
int XMLObject::getClass() const
{
return m_node->getClass() ;
}
uint32 XMLObject::_length() const
{
return m_node->_length();
}
XMLObject *XMLObject::getParent()
{
if (m_node->getParent())
return new (core()->GetGC()) XMLObject (toplevel()->xmlClass(), m_node->getParent());
else
return 0;
}
void XMLObject::setValue(Stringp s)
{
m_node->setValue (s);
}
Stringp XMLObject::getValue()
{
return m_node->getValue();
}
bool XMLObject::getQName(Multiname *m)
{
return m_node->getQName(m, publicNS);
}
Atom XMLObject::AS3_setNotification(FunctionObject* f)
{
AvmCore* core = this->core();
// Notifiers MUST be functions or null
if (f && !AvmCore::istype(f->atom(), core->traits.function_itraits))
toplevel()->throwArgumentError( kInvalidArgumentError, "f");
else
m_node->setNotification(core, f, publicNS);
// since AS3 sez this returns an Atom, our implementation must do so.
return undefinedAtom;
}
FunctionObject* XMLObject::AS3_notification()
{
return m_node->getNotification();
}
bool XMLObject::notifyNeeded(E4XNode* initialTarget)
{
// do a quick probe to see if we need to issue any notifications
bool hit = false;
E4XNode* node = initialTarget;
while(node)
{
if (node->getNotification())
{
hit = true;
break;
}
node = node->getParent();
}
return hit;
}
/**
* Notification on generic node addition from XML or XMLList
*/
void XMLObject::childChanges(Stringp type, Atom value, E4XNode* prior)
{
AvmCore* core = this->core();
Toplevel* top = this->toplevel();
E4XNode* initialTarget = m_node;
if (notifyNeeded(initialTarget))
{
XMLObject* target = new (core->GetGC()) XMLObject(top->xmlClass(), initialTarget);
Atom detail = undefinedAtom;
if (prior)
{
XMLObject* xml = new (core->GetGC()) XMLObject(xmlClass(), prior);
detail = xml->atom();
}
if (AvmCore::isXML(value))
{
issueNotifications(core, top, initialTarget, target->atom(), type, value, detail);
}
else if (AvmCore::isXMLList(value))
{
// if its a list each element in the list is added.
XMLListObject* xl = AvmCore::atomToXMLList(value);
if (xl)
{
issueNotifications(core, top, initialTarget, target->atom(), type, xl->atom(), detail);
}
else
{
AvmAssert(false);
}
}
else
{
// non child updates
}
}
}
void XMLObject::nonChildChanges(Stringp type, Atom value, Atom detail)
{
AvmCore* core = this->core();
Toplevel* top = this->toplevel();
E4XNode* initialTarget = m_node;
if (notifyNeeded(initialTarget))
{
XMLObject* target = new (core->GetGC()) XMLObject(top->xmlClass(), initialTarget);
issueNotifications(core, top, initialTarget, target->atom(), type, value, detail);
}
}
/**
* Perform the callback for each node in which the notification property is set.
*/
void XMLObject::issueNotifications(AvmCore* core, Toplevel* top, E4XNode* initialTarget, Atom target, Stringp type, Atom value, Atom detail)
{
// start notification at initialtarget
E4XNode* volatile node = initialTarget;
while(node)
{
// check if notification param set
ScriptObject* methodObj = node->getNotification();
if (methodObj)
{
XMLObject* currentTarget = new (core->GetGC()) XMLObject(top->xmlClass(), node);
Atom argv[6] = { top->atom(), currentTarget->atom(), type->atom(), target, value, detail };
int argc = 5;
//EnterScriptTimeout enterScriptTimeout(core);
TRY(core, kCatchAction_Rethrow)
{
methodObj->call(argc, argv);
}
CATCH(Exception *exception)
{
// you chuck, we chuck
core->throwException(exception);
}
END_CATCH
END_TRY
}
// bubble up
node = node->getParent();
}
}
#ifdef XML_FILTER_EXPERIMENT
XMLListObject * XMLObject::filter (Atom propertyName, Atom value)
{
Multiname m;
toplevel()->ToXMLName(propertyName, m);
Multiname name;
toplevel()->CoerceE4XMultiname(&m, name);
// filter opcode experiment
XMLListObject *l = new (core()->gc) XMLListObject(toplevel()->xmlListClass(), nullObjectAtom);
this->_filter (l, name, value);
return l;
}
void XMLObject::_filter (XMLListObject *l, const Multiname &name, Atom value)
{
AvmCore *core = this->core();
if (!name.isAnyName())
{
// We have an integer argument - direct child lookup
Stringp nameString = name.getName();
uint32 index;
if (AvmCore::getIndexFromString (nameString, &index))
{
if (index == 0)
{
if (core->equals (this->atom(), value))
{
l->_append (this->getNode());
}
}
}
}
if (name.isAttr())
{
// for each a in x.[[attributes]]
for (uint32 i = 0; i < m_node->numAttributes(); i++)
{
E4XNode *xml = m_node->getAttribute(i);
AvmAssert(xml && xml->getClass() == E4XNode::kAttribute);
Multiname m;
AvmAssert(xml->getQName(&m, publicNS) != 0);
xml->getQName(&m, publicNS);
if (name.matches(&m))
{
if (core->equals(xml->getValue()->atom(), value) == trueAtom)
l->_append (xml);
}
}
return;
}
for (uint32 i = 0; i < m_node->numChildren(); i++)
{
E4XNode *child = m_node->_getAt(i);
Multiname m;
Multiname *m2 = 0;
if (child->getClass() == E4XNode::kElement)
{
child->getQName(&m, publicNS);
m2 = &m;
}
if (name.matches(m2))
{
// If we're an element node, we do something more complicated than a string compare
if (child->getClass() == E4XNode::kElement)
{
// Hacky swaping of our XMLObject's node ptr to point to the child
// node so we can call out to AvmCore::eq with an atom.
E4XNode *savedNode = this->m_node;
this->m_node = child;
if (core->equals(this->atom(), value) == trueAtom)
l->_append (child);
this->m_node = savedNode;
}
else
{
// !!@ this needs testing with comments/PI/text/etc.
if (core->equals(child->getValue()->atom(), value) == trueAtom)
l->_append (child);
}
}
}
}
#endif // XML_FILTER_EXPERIMENT
void XMLObject::dispose()
{
m_node->dispose();
}
#ifdef DEBUGGER
/*override*/ uint64_t XMLObject::bytesUsed() const
{
// FIXME As described in https://bugzilla.mozilla.org/show_bug.cgi?id=552307 ,
// this implementation can cause the same memory to be accounted for more
// than once in the profiler. It is easy for the user to have multiple
// XMLLists and XMLs that point into the same tree of E4XNodes. For now,
// there is not much we can do about this. A possible fix is described in
// https://bugzilla.mozilla.org/show_bug.cgi?id=558385
return bytesUsedShallow() + m_node->bytesUsed();
}
uint64_t XMLObject::bytesUsedShallow() const
{
return ScriptObject::bytesUsed();
}
#endif
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
QNameObject::QNameObject (QNameClass *factory, const Multiname &name)
: ScriptObject(factory->ivtable(), factory->prototypePtr()), m_mn(name)
{
}
/**
* QNameObject is used to represent the "QName" object in the E4X Specification.
*
* We also use this same object to represent "AttributeName" in the E4X spec.
* An AttributeName is simply a QName wrapper for finding properties that have a leading @ sign.
* It's an internal class to the spec and the only difference between a QName is the @. Instead of
* having the overhead of an AttributeName class that wraps the QName class, we just use a boolean
* inside the QName to differentiate betweent the two types.
*/
QNameObject::QNameObject(QNameClass *factory, Namespace *ns, Atom nameatom, bool bA)
: ScriptObject(factory->ivtable(), factory->prototypePtr())
{
AvmCore *core = this->core();
Stringp name;
if (AvmCore::isQName(nameatom))
{
QNameObject *q = AvmCore::atomToQName(nameatom);
name = q->m_mn.getName();
}
else if (nameatom == undefinedAtom)
{
name = core->kEmptyString;
}
else
{
name = core->intern(nameatom);
}
Multiname mn;
// Set attribute bit in multiname
if (bA)
mn.setAttr();
if (name == core->kAsterisk)
{
mn.setAnyName();
AvmAssert(mn.isAnyName());
}
else
{
mn.setName(name);
}
if (ns == NULL)
{
mn.setAnyNamespace();
}
else
{
mn.setNamespace(core->internNamespace(ns));
mn.setQName();
}
this->m_mn = mn;
}
/**
* called when no namespace specified.
*/
QNameObject::QNameObject(QNameClass *factory, Atom nameatom, bool bA)
: ScriptObject(factory->ivtable(), factory->prototypePtr())
{
AvmCore *core = this->core();
Toplevel* toplevel = this->toplevel();
Multiname mn;
if (AvmCore::isQName(nameatom))
{
QNameObject *q = AvmCore::atomToQName(nameatom);
mn = q->m_mn;
}
else
{
Stringp name = core->intern(nameatom);
if (name == core->kAsterisk)
{
mn.setAnyNamespace();
mn.setAnyName();
AvmAssert(mn.isAnyName());
}
else
{
if (nameatom == undefinedAtom)
{
mn.setName(core->kEmptyString);
}
else
{
mn.setName(name);
}
Namespacep ns = ApiUtils::getVersionedNamespace(core, toplevel->getDefaultNamespace(), core->getAPI(NULL));
mn.setNamespace(ns);
}
}
// Set attribute bit in multiname
if (bA)
mn.setAttr();
this->m_mn = mn;
}
Stringp QNameObject::get_localName() const
{
if (this->m_mn.isAnyName())
return core()->kAsterisk;
return m_mn.getName();
}
Atom QNameObject::getURI() const
{
if (m_mn.isAnyNamespace())
{
return nullStringAtom;
}
else if (m_mn.namespaceCount() > 1)
{
return core()->kEmptyString->atom();
}
else
{
return m_mn.getNamespace()->getURI()->atom();
}
}
Atom QNameObject::get_uri() const
{
return getURI();
}
// E4X 13.3.5.4, pg 69
Namespace *XMLObject::GetNamespace (const Multiname &mn, const AtomArray *nsArray) const
{
AvmCore *core = this->core();
AvmAssert(!mn.isAnyNamespace());
Stringp uri = mn.getNamespace()->getURI();
if (nsArray)
{
for (uint32 i = 0; i < nsArray->getLength(); i++)
{
Namespace *ns = AvmCore::atomToNamespace (nsArray->getAt(i));
AvmAssert(ns!=NULL);
#ifdef STRING_DEBUG
Stringp s1 = ns->getURI();
Stringp s2 = uri;
#endif // STRING_DEBUG
if (ns->getURI() == uri)
{
return ns;
}
}
}
// not found, return empty namespace based upon this QName's uri.
return core->newNamespace (uri->atom());
}
// Iterator support - for in, for each
Atom QNameObject::nextName(int index)
{
AvmAssert(index > 0);
// first return "uri" then "localName"
if (index == 1)
return toplevel()->qnameClass()->kUri;
else if (index == 2)
return toplevel()->qnameClass()->kLocalName;
else
return nullObjectAtom;
}
Atom QNameObject::nextValue(int index)
{
AvmAssert(index > 0);
// first return uri then localName
if (index == 1)
return this->get_localName()->atom();
else if (index == 2)
return this->getURI();
else
return nullStringAtom;
}
int QNameObject::nextNameIndex(int index)
{
AvmAssert(index >= 0);
if (index < 2)
return index + 1;
else
return 0;
}
}
| [
"mason@masonchang.com"
] | mason@masonchang.com |
1eee3984b3246ce87302c59d505c39fc06505886 | 540bf26df5570f7dfe9f3dca52769bdc594dbaa5 | /src/game/server/ai_squad.h | e737045966091b5b0bf354907a47c5397f8edce4 | [] | no_license | InfoSmart/InSource-Singleplayer | c7a8e0de648c4fafcebc4d7ec78e46ad8afd742c | 55e6fb30252d5ff4d19fb7c9d146bfec56055ad4 | refs/heads/master | 2021-01-17T05:46:39.867026 | 2013-07-07T06:13:41 | 2013-07-07T06:13:41 | 7,018,102 | 2 | 0 | null | null | null | null | WINDOWS-1252 | C++ | false | false | 7,847 | h | //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Squad classes
//
//=============================================================================//
#ifndef AI_SQUAD_H
#define AI_SQUAD_H
#include "ai_memory.h"
#include "ai_squadslot.h"
#include "bitstring.h"
class CAI_Squad;
typedef CHandle<CAI_BaseNPC> AIHANDLE;
#define PER_ENEMY_SQUADSLOTS 1
//-----------------------------------------------------------------------------
DECLARE_POINTER_HANDLE(AISquadsIter_t);
DECLARE_POINTER_HANDLE(AISquadIter_t);
#define MAX_SQUAD_MEMBERS 100
#define MAX_SQUAD_DATA_SLOTS 4
//-----------------------------------------------------------------------------
// CAI_SquadManager
//
// Purpose: Manages all the squads in the system
//
//-----------------------------------------------------------------------------
class CAI_SquadManager
{
public:
CAI_SquadManager()
{
m_pSquads = NULL;
}
CAI_Squad * GetFirstSquad( AISquadsIter_t *pIter );
CAI_Squad * GetNextSquad( AISquadsIter_t *pIter );
int NumSquads();
CAI_Squad * FindSquad( string_t squadName ); // Returns squad of the given name
CAI_Squad * CreateSquad( string_t squadName ); // Returns squad of the given name
CAI_Squad * FindCreateSquad( string_t squadName ); // Returns squad of the given name
CAI_Squad * FindCreateSquad( CAI_BaseNPC *pNPC, string_t squadName ); // Returns squad of the given name
void DeleteSquad( CAI_Squad *pSquad );
void DeleteAllSquads(void);
private:
CAI_Squad * m_pSquads; // A linked list of all squads
};
//-------------------------------------
extern CAI_SquadManager g_AI_SquadManager;
//-----------------------------------------------------------------------------
#ifdef PER_ENEMY_SQUADSLOTS
struct AISquadEnemyInfo_t
{
EHANDLE hEnemy;
CBitVec<MAX_SQUADSLOTS> slots; // What squad slots are filled?
DECLARE_SIMPLE_DATADESC();
};
#endif
//-----------------------------------------------------------------------------
// CAI_Squad
//
// Purpose: Tracks enemies, squad slots, squad members
//
//-----------------------------------------------------------------------------
class CAI_Squad
{
public:
const char * GetName() const { return STRING(m_Name); }
void RemoveFromSquad( CAI_BaseNPC *pNPC, bool bDeath = false );
CAI_BaseNPC * GetFirstMember( AISquadIter_t *pIter = NULL, bool bIgnoreSilentMembers = true );
CAI_BaseNPC * GetNextMember( AISquadIter_t *pIter, bool bIgnoreSilentMembers = true );
CAI_BaseNPC * GetAnyMember();
int NumMembers( bool bIgnoreSilentMembers = true );
int GetSquadIndex( CAI_BaseNPC * );
void SquadNewEnemy ( CBaseEntity *pEnemy );
void UpdateEnemyMemory( CAI_BaseNPC *pUpdater, CBaseEntity *pEnemy, const Vector &position );
bool OccupyStrategySlotRange( CBaseEntity *pEnemy, int slotIDStart, int slotIDEnd, int *pSlot );
void VacateStrategySlot( CBaseEntity *pEnemy, int slot);
bool IsStrategySlotRangeOccupied( CBaseEntity *pEnemy, int slotIDStart, int slotIDEnd );
CAI_BaseNPC * SquadMemberInRange( const Vector &vecLocation, float flDist );
CAI_BaseNPC * NearestSquadMember( CAI_BaseNPC *pMember );
int GetVisibleSquadMembers( CAI_BaseNPC *pMember );
CAI_BaseNPC * GetSquadMemberNearestTo( const Vector &vecLocation );
bool SquadIsMember( CBaseEntity *pMember );
bool IsLeader( CAI_BaseNPC *pLeader );
CAI_BaseNPC *GetLeader( void );
int BroadcastInteraction( int interactionType, void *data, CBaseCombatCharacter *sender = NULL );
void AddToSquad(CAI_BaseNPC *pNPC);
bool FOkToMakeSound( int soundPriority );
void JustMadeSound( int soundPriority, float time );
float GetSquadSoundWaitTime() const { return m_flSquadSoundWaitTime; }
void SetSquadSoundWaitTime( float time ) { m_flSquadSoundWaitTime = time; }
void SquadRemember( int iMemory );
void SetSquadInflictor( CBaseEntity *pInflictor );
bool IsSquadInflictor( CBaseEntity *pInflictor );
static bool IsSilentMember( const CAI_BaseNPC *pNPC );
template <typename T>
void SetSquadData( unsigned slot, const T &data )
{
Assert( slot < MAX_SQUAD_DATA_SLOTS );
if ( slot < MAX_SQUAD_DATA_SLOTS )
{
m_SquadData[slot] = *((int *)&data);
}
}
template <typename T>
void GetSquadData( unsigned slot, T *pData )
{
Assert( slot < MAX_SQUAD_DATA_SLOTS );
if ( slot < MAX_SQUAD_DATA_SLOTS )
{
*pData = *((T *)&m_SquadData[slot]);
}
}
private:
void OccupySlot( CBaseEntity *pEnemy, int i );
void VacateSlot( CBaseEntity *pEnemy, int i );
bool IsSlotOccupied( CBaseEntity *pEnemy, int i ) const;
private:
friend class CAI_SaveRestoreBlockHandler;
friend class CAI_SquadManager;
CAI_Squad();
CAI_Squad(string_t squadName);
~CAI_Squad(void);
CAI_Squad* GetNext() { return m_pNextSquad; }
void Init( string_t squadName );
CAI_Squad * m_pNextSquad; // The next squad is list of all squads
string_t m_Name;
CUtlVectorFixed<AIHANDLE, MAX_SQUAD_MEMBERS> m_SquadMembers;
float m_flSquadSoundWaitTime; // Time when I'm allowed to make another sound
int m_nSquadSoundPriority; // if we're still waiting, this is the priority of the current sound
EHANDLE m_hSquadInflictor;
int m_SquadData[MAX_SQUAD_DATA_SLOTS];
#ifdef PER_ENEMY_SQUADSLOTS
AISquadEnemyInfo_t *FindEnemyInfo( CBaseEntity *pEnemy );
const AISquadEnemyInfo_t *FindEnemyInfo( CBaseEntity *pEnemy ) const { return const_cast<CAI_Squad *>(this)->FindEnemyInfo( pEnemy ); }
AISquadEnemyInfo_t * m_pLastFoundEnemyInfo; // Occupy/Vacate need to be reworked to not want this
CUtlVector<AISquadEnemyInfo_t> m_EnemyInfos;
float m_flEnemyInfoCleanupTime;
#else
CVarBitVec m_squadSlotsUsed; // What squad slots are filled?
#endif
//---------------------------------
public:
DECLARE_SIMPLE_DATADESC();
};
//-----------------------------------------------------------------------------
//
// Purpose: CAI_SquadManager inline functions
//
//-----------------------------------------------------------------------------
inline CAI_Squad *CAI_SquadManager::GetFirstSquad( AISquadsIter_t *pIter )
{
*pIter = (AISquadsIter_t)m_pSquads;
return m_pSquads;
}
//-------------------------------------
inline CAI_Squad *CAI_SquadManager::GetNextSquad( AISquadsIter_t *pIter )
{
CAI_Squad *pSquad = (CAI_Squad *)*pIter;
if ( pSquad )
pSquad = pSquad->m_pNextSquad;
*pIter = (AISquadsIter_t)pSquad;
return pSquad;
}
//-------------------------------------
// Purpose: Returns squad of the given name or creates a new squad with the
// given name if none exists and add pNPC to the list of members
//-------------------------------------
inline CAI_Squad *CAI_SquadManager::FindCreateSquad(CAI_BaseNPC *pNPC, string_t squadName)
{
CAI_Squad* pSquad = FindSquad( squadName );
if ( !pSquad )
pSquad = CreateSquad( squadName );
pSquad->AddToSquad( pNPC );
return pSquad;
}
//-----------------------------------------------------------------------------
inline CAI_Squad *CAI_SquadManager::FindCreateSquad(string_t squadName)
{
CAI_Squad* pSquad = FindSquad( squadName );
if ( !pSquad )
pSquad = CreateSquad( squadName );
return pSquad;
}
//-------------------------------------
inline CAI_BaseNPC *CAI_Squad::GetAnyMember()
{
if ( m_SquadMembers.Count() )
return m_SquadMembers[random->RandomInt( 0, m_SquadMembers.Count()-1 )];
return NULL;
}
//-------------------------------------
inline int CAI_Squad::GetSquadIndex( CAI_BaseNPC *pAI )
{
for ( int i = 0; i < m_SquadMembers.Count(); i++ )
{
if ( m_SquadMembers[i] == pAI )
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
#endif // AI_SQUAD_H
| [
"webmaster@infosmart.mx"
] | webmaster@infosmart.mx |
9c2dc1713ce86e072e3420d26657e88b5faa355a | 98b1e51f55fe389379b0db00365402359309186a | /homework_6/problem_2/10x10/0.128/phi | cad892b8e9b21bbf6ffb8aa925480a96b6455aad | [] | no_license | taddyb/597-009 | f14c0e75a03ae2fd741905c4c0bc92440d10adda | 5f67e7d3910e3ec115fb3f3dc89a21dcc9a1b927 | refs/heads/main | 2023-01-23T08:14:47.028429 | 2020-12-03T13:24:27 | 2020-12-03T13:24:27 | 311,713,551 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,690 | /*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 8
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class surfaceScalarField;
location "0.128";
object phi;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 3 -1 0 0 0 0];
internalField nonuniform List<scalar>
180
(
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
0.002
)
;
boundaryField
{
left
{
type calculated;
value nonuniform List<scalar> 10(-0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002);
}
right
{
type calculated;
value nonuniform List<scalar> 10(0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002);
}
up
{
type calculated;
value nonuniform List<scalar> 10(0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002 0.002);
}
down
{
type calculated;
value nonuniform List<scalar> 10(-0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002 -0.002);
}
frontAndBack
{
type empty;
value nonuniform List<scalar> 0();
}
}
// ************************************************************************* //
| [
"tbindas@pop-os.localdomain"
] | tbindas@pop-os.localdomain | |
a2982821c98a9f921581cf5f47da66533e1cf50b | f54fad50b009567c372cf8ffc512b57b972f1658 | /include/bounds.hpp | c95e15ab4b52c39c0c4319b2ad4863c31ef31827 | [] | no_license | coelho-k/badminton_player_tracker | ca9adce4429e747743e04506b99096284a1ff6c4 | 17d9aa5a1d397b382c5b746dee75930ea7d1369a | refs/heads/master | 2023-04-26T23:42:42.087476 | 2021-04-29T14:49:57 | 2021-04-29T14:49:57 | 330,264,080 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 786 | hpp | #ifndef BOUNDS_HPP
#define BOUNDS_HPP
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/video.hpp>
using namespace cv;
using namespace std;
const int thresh = 200;
const int max_thresh = 255;
const int blockSize = 5;
const int apertureSize = 3;
const double k = 0.01;
const float courtWidth = 6.10; // court width
const float courtHeight = 13.4; // court height
// Uses masks to isolate the court and the boundary
Mat courtMask(Mat& frame);
// Gets court boundary lines from mask
vector<Vec4i> getLines(Mat& masked);
// Get reference / edges of court position
void sortLines(vector<Vec4i>& lines);
// Returns the transformation matrix mapping
Mat calibrate(const Mat& frame, const vector<Vec4i>& lines);
#endif | [
"coelho.k@husky.neu.edu"
] | coelho.k@husky.neu.edu |
1f981c09420309187f11e70bc9f7fbf0dade9175 | 3d1a754998553b9064eec08e191047406bb57365 | /eldog-bot/dllmain.cpp | 47846e6b4df667f151c4c28d5e5752f6a6442f49 | [] | no_license | TequilaLime/starcraft-bots | 16abb824dc5eb76f607ef527b3f9a9d4b4456291 | a56171c50fff364309de951f10dacd884e656af2 | refs/heads/master | 2021-01-17T09:19:42.584929 | 2011-04-26T20:33:21 | 2011-04-26T20:33:21 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 566 | cpp | #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <BWAPI.h>
#include "EldogBot.h"
namespace BWAPI
{
Game* Broodwar;
}
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
BWAPI::BWAPI_init();
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) BWAPI::AIModule* newAIModule(BWAPI::Game* game)
{
BWAPI::Broodwar = game;
return new EldogBot();
}
| [
"petersutton2009@gmail.com"
] | petersutton2009@gmail.com |
03d8c5c5783756912526231be23e1f35aca5b647 | 6d1c143787686870c2bd792b75836c5a707dad3f | /Server/CommonCPlus/CommonCPlus/boost/asio/detail/task_io_service_thread_info.hpp | 0e2c18b1e550507fe24e7fcd28cb181bfd4e4b17 | [] | no_license | jakeowner/lastbattle | 66dad639dd0ac43fd46bac7a0005cc157d350cc9 | 22d310f5bca796461678ccf044389ed5f60e03e0 | refs/heads/master | 2021-05-06T18:25:48.932112 | 2017-11-24T08:21:59 | 2017-11-24T08:21:59 | 111,915,246 | 45 | 34 | null | 2017-11-24T12:19:15 | 2017-11-24T12:19:15 | null | UTF-8 | C++ | false | false | 1,277 | hpp | //
// detail/task_io_service_thread_info.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_DETAIL_TASK_IO_SERVICE_THREAD_INFO_HPP
#define BOOST_ASIO_DETAIL_TASK_IO_SERVICE_THREAD_INFO_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/event.hpp>
#include <boost/asio/detail/op_queue.hpp>
#include <boost/asio/detail/thread_info_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
class task_io_service;
class task_io_service_operation;
struct task_io_service_thread_info : public thread_info_base
{
event* wakeup_event;
op_queue<task_io_service_operation> private_op_queue;
long private_outstanding_work;
task_io_service_thread_info* next;
};
} // namespace detail
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_DETAIL_TASK_IO_SERVICE_THREAD_INFO_HPP
| [
"613961636@qq.com"
] | 613961636@qq.com |
f83b7f992474024541a6d01143e68aa7032ff7fc | a5aefd65c28ddf8a27433d982c984f70bc05b268 | /COMP 575 - Introduction to Computer Graphics (Fall 2015)/pa5/src/GCanvas.cpp | d33bec4622820993bfa30dcbfb306a06f38e2098 | [] | no_license | fangelod/Coursework | 63d2bbc7147caf963cfca24c076a3c3822dfa346 | 8306896e98329e06fe7945bcb55d219d4c8a7fcd | refs/heads/master | 2020-12-31T07:43:56.952769 | 2016-05-23T23:18:16 | 2016-05-23T23:18:16 | 59,520,854 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 541 | cpp | /**
* Copyright 2015 Mike Reed
*/
#include "GCanvas.h"
void GCanvas::translate(float tx, float ty) {
const float mat[6] = {
1, 0, tx,
0, 1, ty,
};
this->concat(mat);
}
void GCanvas::scale(float sx, float sy) {
const float mat[6] = {
sx, 0, 0,
0, sy, 0,
};
this->concat(mat);
}
void GCanvas::rotate(float radians) {
const float c = cos(radians);
const float s = sin(radians);
const float mat[6] = {
c, -s, 0,
s, c, 0,
};
this->concat(mat);
}
| [
"dominno@live.unc.edu"
] | dominno@live.unc.edu |
0de03d720bda99e18d6874695752d213d3688bbe | cf7a7bb7ef72a370c8e58398a704f455857479c1 | /src/lmdb/key_stream.h | 8c2fcc267fcccbb62784ed6c64c064b3feb5fb8f | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | mask-project/mask | 0505174d3385afd2f1368ec0dbdab193324def5f | b643c9ae9274c25f3b91a9a8cffc68db87784fc2 | refs/heads/master | 2021-06-27T22:31:07.292597 | 2020-09-21T09:41:28 | 2020-09-21T09:41:28 | 141,809,036 | 2 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 9,623 | h | // Copyright (c) 2018, The Mask Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <boost/range/iterator_range.hpp>
#include <cstdint>
#include <cstring>
#include <iterator>
#include <lmdb.h>
#include <utility>
#include "lmdb/value_stream.h"
#include "span.h"
namespace lmdb
{
/*!
An InputIterator for a fixed-sized LMDB key and value. `operator++`
iterates over keys.
\tparam K Key type in database records.
\tparam V Value type in database records.
\note This meets requirements for an InputIterator only. The iterator
can only be incremented and dereferenced. All copies of an iterator
share the same LMDB cursor, and therefore incrementing any copy will
change the cursor state for all (incrementing an iterator will
invalidate all prior copies of the iterator). Usage is identical
to `std::istream_iterator`.
*/
template<typename K, typename V>
class key_iterator
{
MDB_cursor* cur;
epee::span<const std::uint8_t> key;
void increment()
{
// MDB_NEXT_MULTIPLE doesn't work if only one value is stored :/
if (cur)
key = lmdb::stream::get(*cur, MDB_NEXT_NODUP, sizeof(K), sizeof(V)).first;
}
public:
using value_type = std::pair<K, boost::iterator_range<value_iterator<V>>>;
using reference = value_type;
using pointer = void;
using difference_type = std::size_t;
using iterator_category = std::input_iterator_tag;
//! Construct an "end" iterator.
key_iterator() noexcept
: cur(nullptr), key()
{}
/*!
\param cur Iterate over keys starting at this cursor position.
\throw std::system_error if unexpected LMDB error. This can happen
if `cur` is invalid.
*/
key_iterator(MDB_cursor* cur)
: cur(cur), key()
{
if (cur)
key = lmdb::stream::get(*cur, MDB_GET_CURRENT, sizeof(K), sizeof(V)).first;
}
//! \return True if `this` is one-past the last key.
bool is_end() const noexcept { return key.empty(); }
//! \return True iff `rhs` is referencing `this` key.
bool equal(key_iterator const& rhs) const noexcept
{
return
(key.empty() && rhs.key.empty()) ||
key.data() == rhs.key.data();
}
/*!
Moves iterator to next key or end. Invalidates all prior copies of
the iterator.
*/
key_iterator& operator++()
{
increment();
return *this;
}
/*!
Moves iterator to next key or end.
\return A copy that is already invalidated, ignore
*/
key_iterator operator++(int)
{
key_iterator out{*this};
increment();
return out;
}
//! \pre `!is_end()` \return {current key, current value range}
value_type operator*() const
{
return {get_key(), make_value_range()};
}
//! \pre `!is_end()` \return Current key
K get_key() const noexcept
{
assert(!is_end());
K out;
std::memcpy(std::addressof(out), key.data(), sizeof(out));
return out;
}
/*!
Return a C++ iterator over database values from current cursor
position that will reach `.is_end()` after the last duplicate key
record. Calling `make_iterator()` will return an iterator whose
`operator*` will return an entire value (`V`).
`make_iterator<MASK_FIELD(account, id)>()` will return an
iterator whose `operator*` will return a `decltype(account.id)`
object - the other fields in the struct `account` are never copied
from the database.
\throw std::system_error if LMDB has unexpected errors.
\return C++ iterator starting at current cursor position.
*/
template<typename T = V, typename F = T, std::size_t offset = 0>
value_iterator<T, F, offset> make_value_iterator() const
{
static_assert(std::is_same<T, V>(), "bad MASK_FIELD usage?");
return {cur};
}
/*!
Return a range from current cursor position until last duplicate
key record. Useful in for-each range loops or in templated code
expecting a range of elements. Calling `make_range()` will return
a range of `T` objects. `make_range<MASK_FIELD(account, id)>()`
will return a range of `decltype(account.id)` objects - the other
fields in the struct `account` are never copied from the database.
\throw std::system_error if LMDB has unexpected errors.
\return An InputIterator range over values at cursor position.
*/
template<typename T = V, typename F = T, std::size_t offset = 0>
boost::iterator_range<value_iterator<T, F, offset>> make_value_range() const
{
return {make_value_iterator<T, F, offset>(), value_iterator<T, F, offset>{}};
}
};
/*!
C++ wrapper for a LMDB read-only cursor on a fixed-sized key `K` and
value `V`.
\tparam K key type being stored by each record.
\tparam V value type being stored by each record.
\tparam D cleanup functor for the cursor; usually unique per db/table.
*/
template<typename K, typename V, typename D>
class key_stream
{
std::unique_ptr<MDB_cursor, D> cur;
public:
//! Take ownership of `cur` without changing position. `nullptr` valid.
explicit key_stream(std::unique_ptr<MDB_cursor, D> cur)
: cur(std::move(cur))
{}
key_stream(key_stream&&) = default;
key_stream(key_stream const&) = delete;
~key_stream() = default;
key_stream& operator=(key_stream&&) = default;
key_stream& operator=(key_stream const&) = delete;
/*!
Give up ownership of the cursor. `make_iterator()` and
`make_range()` can still be invoked, but return the empty set.
\return Currently owned LMDB cursor.
*/
std::unique_ptr<MDB_cursor, D> give_cursor() noexcept
{
return {std::move(cur)};
}
/*!
Place the stream back at the first key/value. Newly created
iterators will start at the first value again.
\note Invalidates all current iterators, including those created
with `make_iterator` or `make_range`. Also invalidates all
`value_iterator`s created with `key_iterator`.
*/
void reset()
{
if (cur)
lmdb::stream::get(*cur, MDB_FIRST, 0, 0);
}
/*!
\throw std::system_error if LMDB has unexpected errors.
\return C++ iterator over database keys from current cursor
position that will reach `.is_end()` after the last key.
*/
key_iterator<K, V> make_iterator() const
{
return {cur.get()};
}
/*!
\throw std::system_error if LMDB has unexpected errors.
\return Range from current cursor position until last key record.
Useful in for-each range loops or in templated code
*/
boost::iterator_range<key_iterator<K, V>> make_range() const
{
return {make_iterator(), key_iterator<K, V>{}};
}
};
template<typename K, typename V>
inline
bool operator==(key_iterator<K, V> const& lhs, key_iterator<K, V> const& rhs) noexcept
{
return lhs.equal(rhs);
}
template<typename K, typename V>
inline
bool operator!=(key_iterator<K, V> const& lhs, key_iterator<K, V> const& rhs) noexcept
{
return !lhs.equal(rhs);
}
} // lmdb
| [
"diablax@protonmail.com"
] | diablax@protonmail.com |
f8fcc154499efb0d87d72d24a33ce403c420a67f | edfb435ee89eec4875d6405e2de7afac3b2bc648 | /tags/selenium-2.0-beta-1/jobbie/src/cpp/IEDriver/FindElementCommandHandler.h | cc57790bb21b78faa789723258baae971a59c98a | [
"Apache-2.0"
] | permissive | Escobita/selenium | 6c1c78fcf0fb71604e7b07a3259517048e584037 | f4173df37a79ab6dd6ae3f1489ae0cd6cc7db6f1 | refs/heads/master | 2021-01-23T21:01:17.948880 | 2012-12-06T22:47:50 | 2012-12-06T22:47:50 | 8,271,631 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,161 | h | #ifndef WEBDRIVER_IE_FINDELEMENTCOMMANDHANDLER_H_
#define WEBDRIVER_IE_FINDELEMENTCOMMANDHANDLER_H_
#include <ctime>
#include "BrowserManager.h"
namespace webdriver {
class FindElementCommandHandler : public WebDriverCommandHandler {
public:
FindElementCommandHandler(void) {
}
virtual ~FindElementCommandHandler(void) {
}
protected:
void FindElementCommandHandler::ExecuteInternal(BrowserManager *manager, std::map<std::string, std::string> locator_parameters, std::map<std::string, Json::Value> command_parameters, WebDriverResponse * response) {
if (command_parameters.find("using") == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: using");
return;
} else if (command_parameters.find("value") == command_parameters.end()) {
response->SetErrorResponse(400, "Missing parameter: value");
return;
} else {
ElementWrapper *found_element;
std::wstring mechanism = CA2W(command_parameters["using"].asString().c_str(), CP_UTF8);
std::wstring value = CA2W(command_parameters["value"].asString().c_str(), CP_UTF8);
ElementFinder *finder;
int status_code = manager->GetElementFinder(mechanism, &finder);
if (status_code != SUCCESS) {
response->SetErrorResponse(status_code, "Unknown finder mechanism: " + command_parameters["using"].asString());
return;
}
int timeout(manager->implicit_wait_timeout());
clock_t end = clock() + (timeout / 1000 * CLOCKS_PER_SEC);
if (timeout > 0 && timeout < 1000) {
end += 1 * CLOCKS_PER_SEC;
}
do {
status_code = finder->FindElement(manager, NULL, value, &found_element);
if (status_code == SUCCESS) {
break;
}
} while (clock() < end);
if (status_code == SUCCESS) {
response->SetResponse(SUCCESS, found_element->ConvertToJson());
return;
} else {
response->SetErrorResponse(status_code, "Unable to find element with " + command_parameters["using"].asString() + " == " + command_parameters["value"].asString());
return;
}
}
}
};
} // namespace webdriver
#endif // WEBDRIVER_IE_FINDELEMENTCOMMANDHANDLER_H_
| [
"simon.m.stewart@07704840-8298-11de-bf8c-fd130f914ac9"
] | simon.m.stewart@07704840-8298-11de-bf8c-fd130f914ac9 |
54a470e4b794cfb6505add23ffa9f037d79cf580 | 399b5e377fdd741fe6e7b845b70491b9ce2cccfd | /LLVM_src/libcxx/test/std/containers/views/span.cons/ptr_len.fail.cpp | ad63c69b3ea63f8fe460e6831bb2b73ec631624b | [
"NCSA",
"LLVM-exception",
"MIT",
"Apache-2.0"
] | permissive | zslwyuan/LLVM-9-for-Light-HLS | 6ebdd03769c6b55e5eec923cb89e4a8efc7dc9ab | ec6973122a0e65d963356e0fb2bff7488150087c | refs/heads/master | 2021-06-30T20:12:46.289053 | 2020-12-07T07:52:19 | 2020-12-07T07:52:19 | 203,967,206 | 1 | 3 | null | 2019-10-29T14:45:36 | 2019-08-23T09:25:42 | C++ | UTF-8 | C++ | false | false | 3,349 | cpp | // -*- C++ -*-
//===------------------------------ span ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
// <span>
// constexpr span(pointer ptr, index_type count);
// Requires: [ptr, ptr + count) shall be a valid range.
// If extent is not equal to dynamic_extent, then count shall be equal to extent.
//
#include <span>
#include <cassert>
#include <string>
#include "test_macros.h"
int arr[] = {1,2,3};
const int carr[] = {4,5,6};
volatile int varr[] = {7,8,9};
const volatile int cvarr[] = {1,3,5};
int main ()
{
// We can't check that the size doesn't match - because that's a runtime property
// std::span<int, 2> s1(arr, 3);
// Type wrong
{
std::span<float> s1(arr, 3); // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
std::span<float, 3> s2(arr, 3); // expected-error {{no matching constructor for initialization of 'std::span<float, 3>'}}
}
// CV wrong (dynamically sized)
{
std::span< int> s1{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
std::span< int> s2{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
std::span< int> s3{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
std::span<const int> s4{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
std::span<const int> s5{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
std::span< volatile int> s6{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
std::span< volatile int> s7{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
}
// CV wrong (statically sized)
{
std::span< int,3> s1{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
std::span< int,3> s2{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
std::span< int,3> s3{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
std::span<const int,3> s4{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
std::span<const int,3> s5{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
std::span< volatile int,3> s6{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
std::span< volatile int,3> s7{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
}
}
| [
"tliang@connect.ust.hk"
] | tliang@connect.ust.hk |
077e77f9d1371185bf2dd4f9a765ff26f9d79423 | 60bb67415a192d0c421719de7822c1819d5ba7ac | /blazetest/src/mathtest/dmatsmatmult/LDaMIb.cpp | d917b856ada093d82edf0b706cb57c1c1e49618f | [
"BSD-3-Clause"
] | permissive | rtohid/blaze | 48decd51395d912730add9bc0d19e617ecae8624 | 7852d9e22aeb89b907cb878c28d6ca75e5528431 | refs/heads/master | 2020-04-16T16:48:03.915504 | 2018-12-19T20:29:42 | 2018-12-19T20:29:42 | 165,750,036 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,306 | cpp | //=================================================================================================
/*!
// \file src/mathtest/dmatsmatmult/LDaMIb.cpp
// \brief Source file for the LDaMIb dense matrix/sparse matrix multiplication math test
//
// Copyright (C) 2012-2018 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cstdlib>
#include <iostream>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/math/IdentityMatrix.h>
#include <blaze/math/LowerMatrix.h>
#include <blazetest/mathtest/Creator.h>
#include <blazetest/mathtest/dmatsmatmult/OperationTest.h>
#include <blazetest/system/MathTest.h>
//=================================================================================================
//
// MAIN FUNCTION
//
//=================================================================================================
//*************************************************************************************************
int main()
{
std::cout << " Running 'LDaMIb'..." << std::endl;
using blazetest::mathtest::TypeA;
using blazetest::mathtest::TypeB;
try
{
// Matrix type definitions
using LDa = blaze::LowerMatrix< blaze::DynamicMatrix<TypeA> >;
using MIb = blaze::IdentityMatrix<TypeB>;
// Creator type definitions
using CLDa = blazetest::Creator<LDa>;
using CMIb = blazetest::Creator<MIb>;
// Running tests with small matrices
for( size_t i=0UL; i<=6UL; ++i ) {
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( i ), CMIb( i ) );
}
// Running tests with large matrices
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 31UL ), CMIb( 31UL ) );
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 67UL ), CMIb( 67UL ) );
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 127UL ), CMIb( 127UL ) );
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 32UL ), CMIb( 32UL ) );
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 64UL ), CMIb( 64UL ) );
RUN_DMATSMATMULT_OPERATION_TEST( CLDa( 128UL ), CMIb( 128UL ) );
}
catch( std::exception& ex ) {
std::cerr << "\n\n ERROR DETECTED during dense matrix/sparse matrix multiplication:\n"
<< ex.what() << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//*************************************************************************************************
| [
"klaus.iglberger@gmail.com"
] | klaus.iglberger@gmail.com |
3098cc1cbadea2c65750132ee030f3340a5b64df | b879e7f898ae448e69a75b4efcc570e1675c6865 | /src/PcscEvents/wxWidgets/include/wx/persist/bookctrl.h | a226a18583c42bf21e25dfbc9dc953654cebd67a | [] | no_license | idrassi/pcsctracker | 52784ce0eaf3bbc98bbd524bca397e14fe3cd419 | 5d75b661c8711afe4b66022ddd6ce04c536d6f1c | refs/heads/master | 2021-01-20T00:14:28.208953 | 2017-04-22T16:06:00 | 2017-04-22T16:12:19 | 89,100,906 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,026 | h | ///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/bookctrl.h
// Purpose: persistence support for wxBookCtrl
// Author: Vadim Zeitlin
// Created: 2009-01-19
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_BOOKCTRL_H_
#define _WX_PERSIST_BOOKCTRL_H_
#include "wx/persist/window.h"
#include "wx/bookctrl.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentBookCtrl
// ----------------------------------------------------------------------------
#define wxPERSIST_BOOK_KIND "Book"
#define wxPERSIST_BOOK_SELECTION "Selection"
// ----------------------------------------------------------------------------
// wxPersistentBookCtrl: supports saving/restoring book control selection
// ----------------------------------------------------------------------------
class wxPersistentBookCtrl : public wxPersistentWindow<wxBookCtrlBase>
{
public:
wxPersistentBookCtrl(wxBookCtrlBase *book)
: wxPersistentWindow<wxBookCtrlBase>(book)
{
}
virtual void Save() const
{
SaveValue(wxPERSIST_BOOK_SELECTION, Get()->GetSelection());
}
virtual bool Restore()
{
long sel;
if ( RestoreValue(wxPERSIST_BOOK_SELECTION, &sel) )
{
wxBookCtrlBase * const book = Get();
if ( sel >= 0 && (unsigned)sel < book->GetPageCount() )
{
book->SetSelection(sel);
return true;
}
}
return false;
}
virtual wxString GetKind() const { return wxPERSIST_BOOK_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxBookCtrlBase *book)
{
return new wxPersistentBookCtrl(book);
}
#endif // _WX_PERSIST_BOOKCTRL_H_
| [
"mounir.idrassi@idrix.fr"
] | mounir.idrassi@idrix.fr |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.